-1

What is the meaning of -Wextra in clang compiler flag?

I was curious what does all the flags such as -Wall, -Werror means. I was able to find answers for others, but not -Wextra.

clang -Wall -Wextra -Werror
  • 4
    `-Wall` enables all warnings, except not actually all of them. The rest are in `-Wextra`, except not all of the rest. We have `-Weverything`, too, for that. – Ry- Sep 06 '19 at 22:01
  • -Werror treats warnings as errors, i.e. they abort the compilation. – William McBrine Sep 06 '19 at 22:05
  • 4
    How did you not find the official documentation: https://clang.llvm.org/docs/DiagnosticsReference.html#wextra ? – bolov Sep 06 '19 at 22:09
  • 3
    Possible duplicate of [What warnings are included in Clang's -Wall and -Wextra?](https://stackoverflow.com/questions/24904101/what-warnings-are-included-in-clangs-wall-and-wextra) – Schwern Sep 06 '19 at 22:09
  • 1
    @bolov: this is Stack Overflow, **The** Internet Source For Manual Searches :-/ – Bob Jarvis - Слава Україні Sep 06 '19 at 22:25
  • I did find the official document, but did not realize what it meant. Now I get it with the help of comments and the answer. Thanks! –  Sep 06 '19 at 22:39
  • 1
    @bolov: What use is that documentation? It says “Some of the diagnostics controlled by this flag are enabled by default.” “Some”? What use is “some”? It tells us nothing. It then tells us “Also controls…” but does not fill in the “some”. Hey, here is a program. It is fully documented to do “something.” – Eric Postpischil Sep 06 '19 at 23:10

2 Answers2

2

-Wextra flag is not specific to just the clang compiler, it is documented in the GCC Compiler as well. Basically, -Wall enables all (common) warning flags but this excludes many flags.

Some of these, notably -Wempty-init-stmt, -Wignored-qualifiers, -Winitializer-overrides, -Wmissing-field-initializers, -Wmissing-method-return-type, -Wnull-pointer-arithmetic, -Wsemicolon-before-method-body, -Wsign-compare, -Wunused-parameter are covered by -Wextra instead.

You can find out more about what each of these mean in the documentation.

Zain Arshad
  • 1,885
  • 1
  • 11
  • 26
  • New users must take this to account, that if they find the answer correct and it resolves their issue, then kindly mark that as answer. so that if someone have the same issue in future they can get a handy help without asking a new question. That's how things work here . Welcome to SO :) – Zain Arshad Sep 07 '19 at 08:40
2

-Wextra compiler flag is not just in clang but also in gcc. According to the gcc docs:

This enables some extra warning flags that are not enabled by -Wall. This option used to be called -W. The older name is still supported, but the newer name is more descriptive.

Source:

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Waqar
  • 8,558
  • 4
  • 35
  • 43