GCC 4.1.2
-Wextra
- A function can return either with or without a value. (Falling off the end of the function body is considered
- returning without a value.) For example, this function would evoke such a warning:
- foo (a) {
if (a > 0)
- return a;
- foo (a) {
- An expression-statement or the left-hand side of a comma expression contains no side effects. To suppress the
- warning, cast the unused expression to void. For example, an expression such as x[i,j] will cause a warning, but x[(void)i,j] will not.
An unsigned value is compared against zero with < or >=.
- Storage-class specifiers like "static" are not the first things in a declaration. According to the C Standard,
- this usage is obsolescent.
- If -Wall or -Wunused is also specified, warn about unused arguments.
- A comparison between signed and unsigned values could produce an incorrect result when the signed value is con‐
- verted to unsigned. (But don’t warn if -Wno-sign-compare is also specified.)
- An aggregate has an initializer which does not initialize all members. This warning can be independently con‐
- trolled by -Wmissing-field-initializers.
A function parameter is declared without a type specifier in K&R-style functions:
- void foo(bar) { }
- An empty body occurs in an if or else statement.
A pointer is compared against integer zero with <, <=, >, or >=.
- A variable might be changed by longjmp or vfork.
- Any of several floating-point events that often indicate errors, such as overflow, underflow, loss of precision,
- etc.
<(C++ only)>
- An enumerator and a non-enumerator both appear in a conditional expression.
<(C++ only)>
- A non-static reference or non-static const member appears in a class without constructors.
<(C++ only)>
- Ambiguous virtual bases.
<(C++ only)>
- Subscripting an array which has been declared register.
<(C++ only)>
- Taking the address of a variable which has been declared register.
<(C++ only)>
- A base class is not initialized in a derived class’ copy constructor.
- returning without a value.) For example, this function would evoke such a warning:
Other mentions of Wextra:
- -Wunused
- All the above -Wunused options combined. In order to get a warning about an unused function parameter, you must either specify -Wextra -Wunused (note that -Wall implies -Wunused), or separately specify -Wunused-parameter.
- -Wsign-compare
- Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. This warning is also enabled by -Wextra; to get the other warnings of -Wextra without this warning, use -Wextra -Wno-sign-compare.
- -Wmissing-field-initializers
- Warn if a structure’s initializer has some fields missing. For example, the following code would cause such a warn‐ ing, because "x.h" is implicitly zero:
- struct s { int f, g, h; }; struct s x = { 3, 4 };
- struct s { int f, g, h; }; struct s x = { .f = 3, .g = 4 };
- Warn if a structure’s initializer has some fields missing. For example, the following code would cause such a warn‐ ing, because "x.h" is implicitly zero:
Random Ideas for a far distant future:
- Follow -0? description:
- First describe group options (-Wall, -Wextra) and which options they enable (-Wall enables -Wwhatever, -Wanother, )
- Each individual option mentions which group option enables it.
Describe how to disable options once before the list of options. No need to repeat it for each option. There is already a description for Warning options and another for optimisation flags. They could be improved.