Warnings are diagnostic messages that report constructions that are not inherently erroneous but that are risky or suggest there may have been an error.
The following language-independent options do not enable specific warnings but control the kinds of diagnostics produced by GCC.
-fsyntax-only
-fmax-errors=
n-w
-Werror
-Werror=
The warning message for each controllable warning includes the option that controls the warning. That option can then be used with -Werror= and -Wno-error= as described above. (Printing of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)
Note that specifying -Werror=foo automatically implies
-Wfoo. However, -Wno-error=foo does not
imply anything.
-Wfatal-errors
You can request many specific warnings with options beginning with ‘-W’, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ‘-Wno-’ to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. For further language-specific options also refer to C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.
When an unrecognized warning option is requested (e.g., -Wunknown-warning), GCC emits a diagnostic stating that the option is not recognized. However, if the -Wno- form is used, the behavior is slightly different: no diagnostic is produced for -Wno-unknown-warning unless other diagnostics are being produced. This allows the use of new -Wno- options with old compilers, but if something goes wrong, the compiler warns that an unrecognized option is present.
-Wpedantic
-pedantic
Valid ISO C and ISO C++ programs should compile properly with or without this option (though a rare few require -ansi or a -std option specifying the required version of ISO C). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.
-Wpedantic does not cause warning messages for use of the
alternate keywords whose names begin and end with ‘__’. Pedantic
warnings are also disabled in the expression that follows
__extension__
. However, only system header files should use
these escape routes; application programs should avoid them.
See Alternate Keywords.
Some users try to use -Wpedantic to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all—only those for which ISO C requires a diagnostic, and some others for which diagnostics have been added.
A feature to report any failure to conform to ISO C might be useful in some instances, but would require considerable additional work and would be quite different from -Wpedantic. We don't have plans to support such a feature in the near future.
Where the standard specified with -std represents a GNU
extended dialect of C, such as ‘gnu90’ or ‘gnu99’, there is a
corresponding base standard, the version of ISO C on which the GNU
extended dialect is based. Warnings from -Wpedantic are given
where they are required by the base standard. (It does not make sense
for such warnings to be given only for features not in the specified GNU
C dialect, since by definition the GNU dialects of C include all
features the compiler supports with the given option, and there would be
nothing to warn about.)
-pedantic-errors
-Wall
-Wall turns on the following warning flags:
-Waddress -Warray-bounds (only with -O2) -Wc++11-compat -Wchar-subscripts -Wenum-compare (in C/ObjC; this is on by default in C++) -Wimplicit-int (C and Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) -Wcomment -Wformat -Wmain (only for C/ObjC and unless -ffreestanding) -Wmaybe-uninitialized -Wmissing-braces (only for C/ObjC) -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare (only in C++) -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var
Note that some warning flags are not implied by -Wall. Some of
them warn about constructions that users generally do not consider
questionable, but which occasionally you might wish to check for;
others warn about constructions that are necessary or hard to avoid in
some cases, and there is no simple way to modify the code to suppress
the warning. Some of them are enabled by -Wextra but many of
them must be enabled individually.
-Wextra
-Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-parameter (only with -Wunused or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall)
The option -Wextra also prints warning messages for the following cases:
-Wchar-subscripts
char
. This is a common cause
of error, as programmers often forget that this type is signed on some
machines.
This warning is enabled by -Wall.
-Wcomment
-Wno-coverage-mismatch
-Wno-cpp
Suppress warning messages emitted by #warning
directives.
-Wdouble-promotion
(C, C++, Objective-C and Objective-C++ only)float
is implicitly
promoted to double
. CPUs with a 32-bit “single-precision”
floating-point unit implement float
in hardware, but emulate
double
in software. On such a machine, doing computations
using double
values is much more expensive because of the
overhead required for software emulation.
It is easy to accidentally do computations with double
because
floating-point literals are implicitly of type double
. For
example, in:
float area(float radius) { return 3.14159 * radius * radius; }
the compiler performs the entire computation with double
because the floating-point literal is a double
.
-Wformat
-Wformat=
nprintf
and scanf
, etc., to make sure that
the arguments supplied have types appropriate to the format string
specified, and that the conversions specified in the format string make
sense. This includes standard functions, and others specified by format
attributes (see Function Attributes), in the printf
,
scanf
, strftime
and strfmon
(an X/Open extension,
not in the C standard) families (or other target-specific families).
Which functions are checked without format attributes having been
specified depends on the standard version selected, and such checks of
functions without the attribute specified are disabled by
-ffreestanding or -fno-builtin.
The formats are checked against the format features supported by GNU
libc version 2.2. These include all ISO C90 and C99 features, as well
as features from the Single Unix Specification and some BSD and GNU
extensions. Other library implementations may not support all these
features; GCC does not support warning about features that go beyond a
particular library's limitations. However, if -Wpedantic is used
with -Wformat, warnings are given about format features not
in the selected standard version (but not for strfmon
formats,
since those are not in any version of the C standard). See Options Controlling C Dialect.
-Wformat=1
-Wformat
-Wno-format-contains-nul
-Wno-format-extra-args
printf
or scanf
format function. The C standard specifies
that such arguments are ignored.
Where the unused arguments lie between used arguments that are
specified with ‘$’ operand number specifications, normally
warnings are still given, since the implementation could not know what
type to pass to va_arg
to skip the unused arguments. However,
in the case of scanf
formats, this option suppresses the
warning if the unused arguments are all pointers, since the Single
Unix Specification says that such unused arguments are allowed.
-Wno-format-zero-length
-Wformat=2
-Wformat-nonliteral
va_list
.
-Wformat-security
printf
and scanf
functions where the
format string is not a string literal and there are no format arguments,
as in printf (foo);
. This may be a security hole if the format
string came from untrusted input and contains ‘%n’. (This is
currently a subset of what -Wformat-nonliteral warns about, but
in future warnings may be added to -Wformat-security that are not
included in -Wformat-nonliteral.)
-Wformat-y2k
strftime
formats that may yield only a two-digit year.
-Wnonnull
nonnull
function attribute.
-Wnonnull is included in -Wall and -Wformat. It
can be disabled with the -Wno-nonnull option.
-Winit-self
(C, C++, Objective-C and Objective-C++ only)For example, GCC warns about i
being uninitialized in the
following snippet only when -Winit-self has been specified:
int f() { int i = i; return i; }
This warning is enabled by -Wall in C++.
-Wimplicit-int
(C and Objective-C only)-Wimplicit-function-declaration
(C and Objective-C only)-Wimplicit
(C and Objective-C only)-Wignored-qualifiers
(C and C++ only)const
. For ISO C such a type qualifier has no effect,
since the value returned by a function is not an lvalue.
For C++, the warning is only emitted for scalar types or void
.
ISO C prohibits qualified void
return types on function
definitions, so such return types always receive a warning
even without this option.
This warning is also enabled by -Wextra.
-Wmain
-Wmissing-braces
int a[2][2] = { 0, 1, 2, 3 }; int b[2][2] = { { 0, 1 }, { 2, 3 } };
This warning is enabled by -Wall.
-Wmissing-include-dirs
(C, C++, Objective-C and Objective-C++ only)-Wparentheses
Also warn if a comparison like ‘x<=y<=z’ appears; this is equivalent to ‘(x<=y ? 1 : 0) <= z’, which is a different interpretation from that of ordinary mathematical notation.
Also warn about constructions where there may be confusion to which
if
statement an else
branch belongs. Here is an example of
such a case:
{ if (a) if (b) foo (); else bar (); }
In C/C++, every else
branch belongs to the innermost possible
if
statement, which in this example is if (b)
. This is
often not what the programmer expected, as illustrated in the above
example by indentation the programmer chose. When there is the
potential for this confusion, GCC issues a warning when this flag
is specified. To eliminate the warning, add explicit braces around
the innermost if
statement so there is no way the else
can belong to the enclosing if
. The resulting code
looks like this:
{ if (a) { if (b) foo (); else bar (); } }
Also warn for dangerous uses of the GNU extension to
?:
with omitted middle operand. When the condition
in the ?
: operator is a boolean expression, the omitted value is
always 1. Often programmers expect it to be a value computed
inside the conditional expression instead.
This warning is enabled by -Wall.
-Wsequence-point
The C and C++ standards define the order in which expressions in a C/C++
program are evaluated in terms of sequence points, which represent
a partial ordering between the execution of parts of the program: those
executed before the sequence point, and those executed after it. These
occur after the evaluation of a full expression (one which is not part
of a larger expression), after the evaluation of the first operand of a
&&
, ||
, ? :
or ,
(comma) operator, before a
function is called (but after the evaluation of its arguments and the
expression denoting the called function), and in certain other places.
Other than as expressed by the sequence point rules, the order of
evaluation of subexpressions of an expression is not specified. All
these rules describe only a partial order rather than a total order,
since, for example, if two functions are called within one expression
with no sequence point between them, the order in which the functions
are called is not specified. However, the standards committee have
ruled that function calls do not overlap.
It is not specified when between sequence points modifications to the values of objects take effect. Programs whose behavior depends on this have undefined behavior; the C and C++ standards specify that “Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.”. If a program breaks these rules, the results on any particular implementation are entirely unpredictable.
Examples of code with undefined behavior are a = a++;
, a[n]
= b[n++]
and a[i++] = i;
. Some more complicated cases are not
diagnosed by this option, and it may give an occasional false positive
result, but in general it has been found fairly effective at detecting
this sort of problem in programs.
The standard is worded confusingly, therefore there is some debate over the precise meaning of the sequence point rules in subtle cases. Links to discussions of the problem, including proposed formal definitions, may be found on the GCC readings page, at http://gcc.gnu.org/readings.html.
This warning is enabled by -Wall for C and C++.
-Wno-return-local-addr
-Wreturn-type
int
. Also warn about any return
statement with no
return value in a function whose return type is not void
(falling off the end of the function body is considered returning
without a value), and about a return
statement with an
expression in a function whose return type is void
.
For C++, a function without return type always produces a diagnostic message, even when -Wno-return-type is specified. The only exceptions are ‘main’ and functions defined in system headers.
This warning is enabled by -Wall.
-Wswitch
switch
statement has an index of enumerated type
and lacks a case
for one or more of the named codes of that
enumeration. (The presence of a default
label prevents this
warning.) case
labels outside the enumeration range also
provoke warnings when this option is used (even if there is a
default
label).
This warning is enabled by -Wall.
-Wswitch-default
switch
statement does not have a default
case.
-Wswitch-enum
switch
statement has an index of enumerated type
and lacks a case
for one or more of the named codes of that
enumeration. case
labels outside the enumeration range also
provoke warnings when this option is used. The only difference
between -Wswitch and this option is that this option gives a
warning about an omitted enumeration code even if there is a
default
label.
-Wsync-nand
(C and C++ only)__sync_fetch_and_nand
and __sync_nand_and_fetch
built-in functions are used. These functions changed semantics in GCC 4.4.
-Wtrigraphs
-Wunused-but-set-parameter
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
This warning is also enabled by -Wunused together with
-Wextra.
-Wunused-but-set-variable
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
This warning is also enabled by -Wunused, which is enabled
by -Wall.
-Wunused-function
-Wunused-label
To suppress this warning use the ‘unused’ attribute
(see Variable Attributes).
-Wunused-local-typedefs
(C, Objective-C, C++ and Objective-C++ only)-Wunused-parameter
To suppress this warning use the ‘unused’ attribute
(see Variable Attributes).
-Wno-unused-result
warn_unused_result
(see Function Attributes) does not use
its return value. The default is -Wunused-result.
-Wunused-variable
To suppress this warning use the ‘unused’ attribute
(see Variable Attributes).
-Wunused-value
This warning is enabled by -Wall.
-Wunused
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.
-Wuninitialized
setjmp
call. In C++,
warn if a non-static reference or non-static ‘const’ member
appears in a class without constructors.
If you want to warn about code that uses the uninitialized value of the variable in its own initializer, use the -Winit-self option.
These warnings occur for individual uninitialized or clobbered
elements of structure, union or array variables as well as for
variables that are uninitialized or clobbered as a whole. They do
not occur for variables or elements declared volatile
. Because
these warnings depend on optimization, the exact variables or elements
for which there are warnings depends on the precise optimization
options and version of GCC used.
Note that there may be no warning about a variable that is used only
to compute a value that itself is never used, because such
computations may be deleted by data flow analysis before the warnings
are printed.
-Wmaybe-uninitialized
{ int x; switch (y) { case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; } foo (x); }
If the value of y
is always 1, 2 or 3, then x
is
always initialized, but GCC doesn't know this. To suppress the
warning, you need to provide a default case with assert(0) or
similar code.
This option also warns when a non-volatile automatic variable might be
changed by a call to longjmp
. These warnings as well are possible
only in optimizing compilation.
The compiler sees only the calls to setjmp
. It cannot know
where longjmp
will be called; in fact, a signal handler could
call it at any point in the code. As a result, you may get a warning
even when there is in fact no problem because longjmp
cannot
in fact be called at the place that would cause a problem.
Some spurious warnings can be avoided if you declare all the functions
you use that never return as noreturn
. See Function Attributes.
This warning is enabled by -Wall or -Wextra.
-Wunknown-pragmas
#pragma
directive is encountered that is not understood by
GCC. If this command-line option is used, warnings are even issued
for unknown pragmas in system header files. This is not the case if
the warnings are only enabled by the -Wall command-line option.
-Wno-pragmas
-Wstrict-aliasing
-Wstrict-aliasing=n
Level 1: Most aggressive, quick, least accurate. Possibly useful when higher levels do not warn but -fstrict-aliasing still breaks the code, as it has very few false negatives. However, it has many false positives. Warns for all pointer conversions between possibly incompatible types, even if never dereferenced. Runs in the front end only.
Level 2: Aggressive, quick, not too precise. May still have many false positives (not as many as level 1 though), and few false negatives (but possibly more than level 1). Unlike level 1, it only warns when an address is taken. Warns about incomplete types. Runs in the front end only.
Level 3 (default for -Wstrict-aliasing):
Should have very few false positives and few false
negatives. Slightly slower than levels 1 or 2 when optimization is enabled.
Takes care of the common pun+dereference pattern in the front end:
*(int*)&some_float
.
If optimization is enabled, it also runs in the back end, where it deals
with multiple statement cases using flow-sensitive points-to information.
Only warns when the converted pointer is dereferenced.
Does not warn about incomplete types.
-Wstrict-overflow
-Wstrict-overflow=
nAn optimization that assumes that signed overflow does not occur is perfectly safe if the values of the variables involved are such that overflow never does, in fact, occur. Therefore this warning can easily give a false positive: a warning about code that is not actually a problem. To help focus on important issues, several warning levels are defined. No warnings are issued for the use of undefined signed overflow when estimating how many iterations a loop requires, in particular when determining whether a loop will be executed at all.
-Wstrict-overflow=1
x + 1 > x
to 1
. This level of
-Wstrict-overflow is enabled by -Wall; higher levels
are not, and must be explicitly requested.
-Wstrict-overflow=2
abs (x) >= 0
. This can only be
simplified when -fstrict-overflow is in effect, because
abs (INT_MIN)
overflows to INT_MIN
, which is less than
zero. -Wstrict-overflow (with no level) is the same as
-Wstrict-overflow=2.
-Wstrict-overflow=3
x + 1 > 1
is simplified to x > 0
.
-Wstrict-overflow=4
(x * 10) / 5
is simplified to x * 2
.
-Wstrict-overflow=5
x + 2 > y
is
simplified to x + 1 >= y
. This is reported only at the
highest warning level because this simplification applies to many
comparisons, so this warning level gives a very large number of
false positives.
-Wsuggest-attribute=
[pure
|const
|noreturn
|format
]-Wsuggest-attribute=pure
-Wsuggest-attribute=const
-Wsuggest-attribute=noreturn
pure
, const
or noreturn
. The compiler only warns for
functions visible in other compilation units or (in the case of pure
and
const
) if it cannot prove that the function returns normally. A function
returns normally if it doesn't contain an infinite loop or return abnormally
by throwing, calling abort()
or trapping. This analysis requires option
-fipa-pure-const, which is enabled by default at -O and
higher. Higher optimization levels improve the accuracy of the analysis.
-Wsuggest-attribute=format
-Wmissing-format-attribute
format
attributes. Note these are only possible candidates, not absolute ones.
GCC guesses that function pointers with format
attributes that
are used in assignment, initialization, parameter passing or return
statements should have a corresponding format
attribute in the
resulting type. I.e. the left-hand side of the assignment or
initialization, the type of the parameter variable, or the return type
of the containing function respectively should also have a format
attribute to avoid the warning.
GCC also warns about function definitions that might be
candidates for format
attributes. Again, these are only
possible candidates. GCC guesses that format
attributes
might be appropriate for any function that calls a function like
vprintf
or vscanf
, but this might not always be the
case, and some functions for which format
attributes are
appropriate may not be detected.
-Warray-bounds
-Wno-div-by-zero
-Wsystem-headers
-Wtrampolines
A trampoline is a small piece of data or code that is created at run
time on the stack when the address of a nested function is taken, and
is used to call the nested function indirectly. For some targets, it
is made up of data only and thus requires no special treatment. But,
for most targets, it is made up of code and thus requires the stack
to be made executable in order for the program to work properly.
-Wfloat-equal
The idea behind this is that sometimes it is convenient (for the
programmer) to consider floating-point values as approximations to
infinitely precise real numbers. If you are doing this, then you need
to compute (by analyzing the code, or in some other way) the maximum or
likely maximum error that the computation introduces, and allow for it
when performing comparisons (and when producing output, but that's a
different problem). In particular, instead of testing for equality, you
should check to see whether the two values have ranges that overlap; and
this is done with the relational operators, so equality comparisons are
probably mistaken.
-Wtraditional
(C and Objective-C only)<limits.h>
.
Use of these macros in user code might normally lead to spurious
warnings, however GCC's integrated preprocessor has enough context to
avoid warning in these cases.
switch
statement has an operand of type long
.
static
function declaration follows a static
one.
This construct is not accepted by some traditional C compilers.
__STDC__
to avoid missing
initializer warnings and relies on default initialization to zero in the
traditional C case.
PARAMS
and
VPARAMS
. This warning is also bypassed for nested functions
because that feature is already a GCC extension and thus not relevant to
traditional C compatibility.
-Wtraditional-conversion
(C and Objective-C only)-Wdeclaration-after-statement
(C and Objective-C only)-Wundef
-Wno-endif-labels
-Wshadow
-Wlarger-than=
len-Wframe-larger-than=
lenalloca
, variable-length arrays, or related constructs
is not included by the compiler when determining
whether or not to issue a warning.
-Wno-free-nonheap-object
-Wstack-usage=
lenalloca
, variable-length arrays, or related
constructs is included by the compiler when determining whether or not to
issue a warning.
The message is in keeping with the output of -fstack-usage.
warning: stack usage is 1120 bytes
warning: stack usage might be 1648 bytes
warning: stack usage might be unbounded
-Wunsafe-loop-optimizations
-Wno-pedantic-ms-format
(MinGW targets only)printf
/ scanf
format
width specifiers I32
, I64
, and I
used on Windows targets,
which depend on the MS runtime.
-Wpointer-arith
void
. GNU C assigns these types a size of 1, for
convenience in calculations with void *
pointers and pointers
to functions. In C++, warn also when an arithmetic operation involves
NULL
. This warning is also enabled by -Wpedantic.
-Wtype-limits
-Wbad-function-cast
(C and Objective-C only)int malloc()
is cast to anything *
.
-Wc++-compat
(C and Objective-C only)void *
to a pointer to non-void
type.
-Wc++11-compat
(C++ and Objective-C++ only)-Wcast-qual
const char *
is cast
to an ordinary char *
.
Also warn when making a cast that introduces a type qualifier in an
unsafe way. For example, casting char **
to const char **
is unsafe, as in this example:
/* p is char ** value. */ const char **q = (const char **) p; /* Assignment of readonly string to const char * is OK. */ *q = "string"; /* Now char** pointer points to read-only memory. */ **p = 'b';
-Wcast-align
char *
is cast to
an int *
on machines where integers can only be accessed at
two- or four-byte boundaries.
-Wwrite-strings
const
char[
length]
so that copying the address of one into a
non-const
char *
pointer produces a warning. These
warnings help you find at compile time code that can try to write
into a string constant, but only if you have been very careful about
using const
in declarations and prototypes. Otherwise, it is
just a nuisance. This is why we did not make -Wall request
these warnings.
When compiling C++, warn about the deprecated conversion from string
literals to char *
. This warning is enabled by default for C++
programs.
-Wclobbered
-Wconversion
abs (x)
when
x
is double
; conversions between signed and unsigned,
like unsigned ui = -1
; and conversions to smaller types, like
sqrtf (M_PI)
. Do not warn for explicit casts like abs
((int) x)
and ui = (unsigned) -1
, or if the value is not
changed by the conversion like in abs (2.0)
. Warnings about
conversions between signed and unsigned integers can be disabled by
using -Wno-sign-conversion.
For C++, also warn for confusing overload resolution for user-defined
conversions; and conversions that never use a type conversion
operator: conversions to void
, the same type, a base class or a
reference to them. Warnings about conversions between signed and
unsigned integers are disabled by default in C++ unless
-Wsign-conversion is explicitly enabled.
-Wno-conversion-null
(C++ and Objective-C++ only)NULL
and non-pointer
types. -Wconversion-null is enabled by default.
-Wzero-as-null-pointer-constant
(C++ and Objective-C++ only)nullptr
in C++11.
-Wuseless-cast
(C++ and Objective-C++ only)-Wempty-body
-Wenum-compare
-Wjump-misses-init
(C, Objective-C only)goto
statement or a switch
statement jumps
forward across the initialization of a variable, or jumps backward to a
label after the variable has been initialized. This only warns about
variables that are initialized when they are declared. This warning is
only supported for C and Objective-C; in C++ this sort of branch is an
error in any case.
-Wjump-misses-init is included in -Wc++-compat. It
can be disabled with the -Wno-jump-misses-init option.
-Wsign-compare
-Wsign-conversion
-Wsizeof-pointer-memaccess
sizeof
. This warning warns e.g.
about memset (ptr, 0, sizeof (ptr));
if ptr
is not an array,
but a pointer, and suggests a possible fix, or about
memcpy (&foo, ptr, sizeof (&foo));
. This warning is enabled by
-Wall.
-Waddress
void func(void); if (func)
, and comparisons against the memory
address of a string literal, such as if (x == "abc")
. Such
uses typically indicate a programmer error: the address of a function
always evaluates to true, so their use in a conditional usually
indicate that the programmer forgot the parentheses in a function
call; and comparisons against string literals result in unspecified
behavior and are not portable in C, so they usually indicate that the
programmer intended to use strcmp
. This warning is enabled by
-Wall.
-Wlogical-op
-Waggregate-return
-Wno-aggressive-loop-optimizations
-Wno-attributes
__attribute__
is used, such as
unrecognized attributes, function attributes applied to variables,
etc. This does not stop errors for incorrect use of supported
attributes.
-Wno-builtin-macro-redefined
__TIMESTAMP__
, __TIME__
,
__DATE__
, __FILE__
, and __BASE_FILE__
.
-Wstrict-prototypes
(C and Objective-C only)-Wold-style-declaration
(C and Objective-C only)static
are not the first things in a declaration. This warning
is also enabled by -Wextra.
-Wold-style-definition
(C and Objective-C only)-Wmissing-parameter-type
(C and Objective-C only)void foo(bar) { }
This warning is also enabled by -Wextra.
-Wmissing-prototypes
(C and Objective-C only)-Wmissing-declarations
-Wmissing-field-initializers
x.h
is implicitly zero:
struct s { int f, g, h; }; struct s x = { 3, 4 };
This option does not warn about designated initializers, so the following modification does not trigger a warning:
struct s { int f, g, h; }; struct s x = { .f = 3, .g = 4 };
This warning is included in -Wextra. To get other -Wextra
warnings without this one, use -Wextra -Wno-missing-field-initializers.
-Wno-multichar
-Wnormalized=<none|id|nfc|nfkc>
There are four levels of warning supported by GCC. The default is -Wnormalized=nfc, which warns about any identifier that is not in the ISO 10646 “C” normalized form, NFC. NFC is the recommended form for most uses.
Unfortunately, there are some characters allowed in identifiers by ISO C and ISO C++ that, when turned into NFC, are not allowed in identifiers. That is, there's no way to use these symbols in portable ISO C or C++ and have all your identifiers in NFC. -Wnormalized=id suppresses the warning for these characters. It is hoped that future versions of the standards involved will correct this, which is why this option is not the default.
You can switch the warning off for all characters by writing -Wnormalized=none. You should only do this if you are using some other normalization scheme (like “D”), because otherwise you can easily create bugs that are literally impossible to see.
Some characters in ISO 10646 have distinct meanings but look identical
in some fonts or display methodologies, especially once formatting has
been applied. For instance \u207F
, “SUPERSCRIPT LATIN SMALL
LETTER N”, displays just like a regular n
that has been
placed in a superscript. ISO 10646 defines the NFKC
normalization scheme to convert all these into a standard form as
well, and GCC warns if your code is not in NFKC if you use
-Wnormalized=nfkc. This warning is comparable to warning
about every identifier that contains the letter O because it might be
confused with the digit 0, and so is not the default, but may be
useful as a local coding convention if the programming environment
cannot be fixed to display these characters distinctly.
-Wno-deprecated
-Wno-deprecated-declarations
deprecated
attribute.
-Wno-overflow
-Woverride-init
(C and Objective-C only)This warning is included in -Wextra. To get other
-Wextra warnings without this one, use -Wextra
-Wno-override-init.
-Wpacked
f.x
in struct bar
is misaligned even though struct bar
does not itself
have the packed attribute:
struct foo { int x; char a, b, c, d; } __attribute__((packed)); struct bar { char z; struct foo f; };
-Wpacked-bitfield-compat
packed
attribute
on bit-fields of type char
. This has been fixed in GCC 4.4 but
the change can lead to differences in the structure layout. GCC
informs you when the offset of such a field has changed in GCC 4.4.
For example there is no longer a 4-bit padding between field a
and b
in this structure:
struct foo { char a:4; char b:8; } __attribute__ ((packed));
This warning is enabled by default. Use
-Wno-packed-bitfield-compat to disable this warning.
-Wpadded
-Wredundant-decls
-Wnested-externs
(C and Objective-C only)extern
declaration is encountered within a function.
-Wno-inherited-variadic-ctor
-Winline
The compiler uses a variety of heuristics to determine whether or not
to inline a function. For example, the compiler takes into account
the size of the function being inlined and the amount of inlining
that has already been done in the current function. Therefore,
seemingly insignificant changes in the source program can cause the
warnings produced by -Winline to appear or disappear.
-Wno-invalid-offsetof
(C++ and Objective-C++ only)The restrictions on ‘offsetof’ may be relaxed in a future version
of the C++ standard.
-Wno-int-to-pointer-cast
-Wno-pointer-to-int-cast
(C and Objective-C only)-Winvalid-pch
-Wlong-long
-Wvariadic-macros
-Wvarargs
-Wvector-operation-performance
piecewise
, which means that the
scalar operation is performed on every vector element;
in parallel
, which means that the vector operation is implemented
using scalars of wider type, which normally is more performance efficient;
and as a single scalar
, which means that vector fits into a
scalar type.
-Wno-virtual-move-assign
-Wvla
-Wvolatile-register-var
-Wdisabled-optimization
-Wpointer-sign
(C and Objective-C only)-Wstack-protector
-Wno-mudflap
-Woverlength-strings
The limit applies after string constant concatenation, and does not count the trailing NUL. In C90, the limit was 509 characters; in C99, it was raised to 4095. C++98 does not specify a normative minimum maximum, so we do not diagnose overlength strings in C++.
This option is implied by -Wpedantic, and can be disabled with
-Wno-overlength-strings.
-Wunsuffixed-float-constants
(C and Objective-C only)FLOAT_CONST_DECIMAL64
pragma
from the decimal floating-point extension to C99.