gcc: Warning Options
1
1 3.8 Options to Request or Suppress Warnings
1 ===========================================
1
1 Warnings are diagnostic messages that report constructions that are not
1 inherently erroneous but that are risky or suggest there may have been
1 an error.
1
1 The following language-independent options do not enable specific
1 warnings but control the kinds of diagnostics produced by GCC.
1
1 '-fsyntax-only'
1 Check the code for syntax errors, but don't do anything beyond
1 that.
1
1 '-fmax-errors=N'
1 Limits the maximum number of error messages to N, at which point
1 GCC bails out rather than attempting to continue processing the
1 source code. If N is 0 (the default), there is no limit on the
1 number of error messages produced. If '-Wfatal-errors' is also
1 specified, then '-Wfatal-errors' takes precedence over this option.
1
1 '-w'
1 Inhibit all warning messages.
1
1 '-Werror'
1 Make all warnings into errors.
1
1 '-Werror='
1 Make the specified warning into an error. The specifier for a
1 warning is appended; for example '-Werror=switch' turns the
1 warnings controlled by '-Wswitch' into errors. This switch takes a
1 negative form, to be used to negate '-Werror' for specific
1 warnings; for example '-Wno-error=switch' makes '-Wswitch' warnings
1 not be errors, even when '-Werror' is in effect.
1
1 The warning message for each controllable warning includes the
1 option that controls the warning. That option can then be used
1 with '-Werror=' and '-Wno-error=' as described above. (Printing of
1 the option in the warning message can be disabled using the
1 '-fno-diagnostics-show-option' flag.)
1
1 Note that specifying '-Werror='FOO automatically implies '-W'FOO.
1 However, '-Wno-error='FOO does not imply anything.
1
1 '-Wfatal-errors'
1 This option causes the compiler to abort compilation on the first
1 error occurred rather than trying to keep going and printing
1 further error messages.
1
1 You can request many specific warnings with options beginning with
1 '-W', for example '-Wimplicit' to request warnings on implicit
1 declarations. Each of these specific warning options also has a
1 negative form beginning '-Wno-' to turn off warnings; for example,
1 '-Wno-implicit'. This manual lists only one of the two forms, whichever
1 is not the default. For further language-specific options also refer to
DONTPRINTYET 1 ⇒C++ Dialect Options and *noteObjective-C and Objective-C++
1DONTPRINTYET 1 ⇒C++ Dialect Options and ⇒Objective-C and Objective-C++
Dialect Options.
1
1 Some options, such as '-Wall' and '-Wextra', turn on other options,
1 such as '-Wunused', which may turn on further options, such as
1 '-Wunused-value'. The combined effect of positive and negative forms is
1 that more specific options have priority over less specific ones,
1 independently of their position in the command-line. For options of the
1 same specificity, the last one takes effect. Options enabled or
1 disabled via pragmas (⇒Diagnostic Pragmas) take effect as if they
1 appeared at the end of the command-line.
1
1 When an unrecognized warning option is requested (e.g.,
1 '-Wunknown-warning'), GCC emits a diagnostic stating that the option is
1 not recognized. However, if the '-Wno-' form is used, the behavior is
1 slightly different: no diagnostic is produced for '-Wno-unknown-warning'
1 unless other diagnostics are being produced. This allows the use of new
1 '-Wno-' options with old compilers, but if something goes wrong, the
1 compiler warns that an unrecognized option is present.
1
1 The effectiveness of some warnings depends on optimizations also being
1 enabled. For example '-Wsuggest-final-types' is more effective with
1 link-time optimization and '-Wmaybe-uninitialized' will not warn at all
1 unless optimization is enabled.
1
1 '-Wpedantic'
1 '-pedantic'
1 Issue all the warnings demanded by strict ISO C and ISO C++; reject
1 all programs that use forbidden extensions, and some other programs
1 that do not follow ISO C and ISO C++. For ISO C, follows the
1 version of the ISO C standard specified by any '-std' option used.
1
1 Valid ISO C and ISO C++ programs should compile properly with or
1 without this option (though a rare few require '-ansi' or a '-std'
1 option specifying the required version of ISO C). However, without
1 this option, certain GNU extensions and traditional C and C++
1 features are supported as well. With this option, they are
1 rejected.
1
1 '-Wpedantic' does not cause warning messages for use of the
1 alternate keywords whose names begin and end with '__'. Pedantic
1 warnings are also disabled in the expression that follows
1 '__extension__'. However, only system header files should use
11 these escape routes; application programs should avoid them. ⇒
Alternate Keywords.
1
1 Some users try to use '-Wpedantic' to check programs for strict ISO
1 C conformance. They soon find that it does not do quite what they
1 want: it finds some non-ISO practices, but not all--only those for
1 which ISO C _requires_ a diagnostic, and some others for which
1 diagnostics have been added.
1
1 A feature to report any failure to conform to ISO C might be useful
1 in some instances, but would require considerable additional work
1 and would be quite different from '-Wpedantic'. We don't have
1 plans to support such a feature in the near future.
1
1 Where the standard specified with '-std' represents a GNU extended
1 dialect of C, such as 'gnu90' or 'gnu99', there is a corresponding
1 "base standard", the version of ISO C on which the GNU extended
1 dialect is based. Warnings from '-Wpedantic' are given where they
1 are required by the base standard. (It does not make sense for
1 such warnings to be given only for features not in the specified
1 GNU C dialect, since by definition the GNU dialects of C include
1 all features the compiler supports with the given option, and there
1 would be nothing to warn about.)
1
1 '-pedantic-errors'
1 Give an error whenever the "base standard" (see '-Wpedantic')
1 requires a diagnostic, in some cases where there is undefined
1 behavior at compile-time and in some other cases that do not
1 prevent compilation of programs that are valid according to the
1 standard. This is not equivalent to '-Werror=pedantic', since
1 there are errors enabled by this option and not enabled by the
1 latter and vice versa.
1
1 '-Wall'
1 This enables all the warnings about constructions that some users
1 consider questionable, and that are easy to avoid (or modify to
1 prevent the warning), even in conjunction with macros. This also
11 Dialect Options:: and ⇒Objective-C and Objective-C++ Dialect
Options.
1
1 '-Wall' turns on the following warning flags:
1
1 -Waddress
1 -Warray-bounds=1 (only with -O2)
1 -Wbool-compare
1 -Wbool-operation
1 -Wc++11-compat -Wc++14-compat
1 -Wcatch-value (C++ and Objective-C++ only)
1 -Wchar-subscripts
1 -Wcomment
1 -Wduplicate-decl-specifier (C and Objective-C only)
1 -Wenum-compare (in C/ObjC; this is on by default in C++)
1 -Wformat
1 -Wint-in-bool-context
1 -Wimplicit (C and Objective-C only)
1 -Wimplicit-int (C and Objective-C only)
1 -Wimplicit-function-declaration (C and Objective-C only)
1 -Winit-self (only for C++)
1 -Wlogical-not-parentheses
1 -Wmain (only for C/ObjC and unless -ffreestanding)
1 -Wmaybe-uninitialized
1 -Wmemset-elt-size
1 -Wmemset-transposed-args
1 -Wmisleading-indentation (only for C/C++)
1 -Wmissing-attributes
1 -Wmissing-braces (only for C/ObjC)
1 -Wmultistatement-macros
1 -Wnarrowing (only for C++)
1 -Wnonnull
1 -Wnonnull-compare
1 -Wopenmp-simd
1 -Wparentheses
1 -Wpointer-sign
1 -Wreorder
1 -Wrestrict
1 -Wreturn-type
1 -Wsequence-point
1 -Wsign-compare (only in C++)
1 -Wsizeof-pointer-div
1 -Wsizeof-pointer-memaccess
1 -Wstrict-aliasing
1 -Wstrict-overflow=1
1 -Wstringop-truncation
1 -Wswitch
1 -Wtautological-compare
1 -Wtrigraphs
1 -Wuninitialized
1 -Wunknown-pragmas
1 -Wunused-function
1 -Wunused-label
1 -Wunused-value
1 -Wunused-variable
1 -Wvolatile-register-var
1
1
1 Note that some warning flags are not implied by '-Wall'. Some of
1 them warn about constructions that users generally do not consider
1 questionable, but which occasionally you might wish to check for;
1 others warn about constructions that are necessary or hard to avoid
1 in some cases, and there is no simple way to modify the code to
1 suppress the warning. Some of them are enabled by '-Wextra' but
1 many of them must be enabled individually.
1
1 '-Wextra'
1 This enables some extra warning flags that are not enabled by
1 '-Wall'. (This option used to be called '-W'. The older name is
1 still supported, but the newer name is more descriptive.)
1
1 -Wclobbered
1 -Wcast-function-type
1 -Wempty-body
1 -Wignored-qualifiers
1 -Wimplicit-fallthrough=3
1 -Wmissing-field-initializers
1 -Wmissing-parameter-type (C only)
1 -Wold-style-declaration (C only)
1 -Woverride-init
1 -Wsign-compare (C only)
1 -Wtype-limits
1 -Wuninitialized
1 -Wshift-negative-value (in C++03 and in C99 and newer)
1 -Wunused-parameter (only with -Wunused or -Wall)
1 -Wunused-but-set-parameter (only with -Wunused or -Wall)
1
1
1 The option '-Wextra' also prints warning messages for the following
1 cases:
1
1 * A pointer is compared against integer zero with '<', '<=',
1 '>', or '>='.
1
1 * (C++ only) An enumerator and a non-enumerator both appear in a
1 conditional expression.
1
1 * (C++ only) Ambiguous virtual bases.
1
1 * (C++ only) Subscripting an array that has been declared
1 'register'.
1
1 * (C++ only) Taking the address of a variable that has been
1 declared 'register'.
1
1 * (C++ only) A base class is not initialized in the copy
1 constructor of a derived class.
1
1 '-Wchar-subscripts'
1 Warn if an array subscript has type 'char'. This is a common cause
1 of error, as programmers often forget that this type is signed on
1 some machines. This warning is enabled by '-Wall'.
1
1 '-Wchkp'
1 Warn about an invalid memory access that is found by Pointer Bounds
1 Checker ('-fcheck-pointer-bounds').
1
1 '-Wno-coverage-mismatch'
1 Warn if feedback profiles do not match when using the
1 '-fprofile-use' option. If a source file is changed between
1 compiling with '-fprofile-gen' and with '-fprofile-use', the files
1 with the profile feedback can fail to match the source file and GCC
1 cannot use the profile feedback information. By default, this
1 warning is enabled and is treated as an error.
1 '-Wno-coverage-mismatch' can be used to disable the warning or
1 '-Wno-error=coverage-mismatch' can be used to disable the error.
1 Disabling the error for this warning can result in poorly optimized
1 code and is useful only in the case of very minor changes such as
1 bug fixes to an existing code-base. Completely disabling the
1 warning is not recommended.
1
1 '-Wno-cpp'
1 (C, Objective-C, C++, Objective-C++ and Fortran only)
1
1 Suppress warning messages emitted by '#warning' directives.
1
1 '-Wdouble-promotion (C, C++, Objective-C and Objective-C++ only)'
1 Give a warning when a value of type 'float' is implicitly promoted
1 to 'double'. CPUs with a 32-bit "single-precision" floating-point
1 unit implement 'float' in hardware, but emulate 'double' in
1 software. On such a machine, doing computations using 'double'
1 values is much more expensive because of the overhead required for
1 software emulation.
1
1 It is easy to accidentally do computations with 'double' because
1 floating-point literals are implicitly of type 'double'. For
1 example, in:
1 float area(float radius)
1 {
1 return 3.14159 * radius * radius;
1 }
1 the compiler performs the entire computation with 'double' because
1 the floating-point literal is a 'double'.
1
1 '-Wduplicate-decl-specifier (C and Objective-C only)'
1 Warn if a declaration has duplicate 'const', 'volatile', 'restrict'
1 or '_Atomic' specifier. This warning is enabled by '-Wall'.
1
1 '-Wformat'
1 '-Wformat=N'
1 Check calls to 'printf' and 'scanf', etc., to make sure that the
1 arguments supplied have types appropriate to the format string
1 specified, and that the conversions specified in the format string
1 make sense. This includes standard functions, and others specified
1 by format attributes (⇒Function Attributes), in the
1 'printf', 'scanf', 'strftime' and 'strfmon' (an X/Open extension,
1 not in the C standard) families (or other target-specific
1 families). Which functions are checked without format attributes
1 having been specified depends on the standard version selected, and
1 such checks of functions without the attribute specified are
1 disabled by '-ffreestanding' or '-fno-builtin'.
1
1 The formats are checked against the format features supported by
1 GNU libc version 2.2. These include all ISO C90 and C99 features,
1 as well as features from the Single Unix Specification and some BSD
1 and GNU extensions. Other library implementations may not support
1 all these features; GCC does not support warning about features
1 that go beyond a particular library's limitations. However, if
1 '-Wpedantic' is used with '-Wformat', warnings are given about
1 format features not in the selected standard version (but not for
1 'strfmon' formats, since those are not in any version of the C
1 standard). ⇒Options Controlling C Dialect C Dialect Options.
1
1 '-Wformat=1'
1 '-Wformat'
1 Option '-Wformat' is equivalent to '-Wformat=1', and
1 '-Wno-format' is equivalent to '-Wformat=0'. Since '-Wformat'
1 also checks for null format arguments for several functions,
1 '-Wformat' also implies '-Wnonnull'. Some aspects of this
1 level of format checking can be disabled by the options:
1 '-Wno-format-contains-nul', '-Wno-format-extra-args', and
1 '-Wno-format-zero-length'. '-Wformat' is enabled by '-Wall'.
1
1 '-Wno-format-contains-nul'
1 If '-Wformat' is specified, do not warn about format strings
1 that contain NUL bytes.
1
1 '-Wno-format-extra-args'
1 If '-Wformat' is specified, do not warn about excess arguments
1 to a 'printf' or 'scanf' format function. The C standard
1 specifies that such arguments are ignored.
1
1 Where the unused arguments lie between used arguments that are
1 specified with '$' operand number specifications, normally
1 warnings are still given, since the implementation could not
1 know what type to pass to 'va_arg' to skip the unused
1 arguments. However, in the case of 'scanf' formats, this
1 option suppresses the warning if the unused arguments are all
1 pointers, since the Single Unix Specification says that such
1 unused arguments are allowed.
1
1 '-Wformat-overflow'
1 '-Wformat-overflow=LEVEL'
1 Warn about calls to formatted input/output functions such as
1 'sprintf' and 'vsprintf' that might overflow the destination
1 buffer. When the exact number of bytes written by a format
1 directive cannot be determined at compile-time it is estimated
1 based on heuristics that depend on the LEVEL argument and on
1 optimization. While enabling optimization will in most cases
1 improve the accuracy of the warning, it may also result in
1 false positives.
1
1 '-Wformat-overflow'
1 '-Wformat-overflow=1'
1 Level 1 of '-Wformat-overflow' enabled by '-Wformat'
1 employs a conservative approach that warns only about
1 calls that most likely overflow the buffer. At this
1 level, numeric arguments to format directives with
1 unknown values are assumed to have the value of one, and
1 strings of unknown length to be empty. Numeric arguments
1 that are known to be bounded to a subrange of their type,
1 or string arguments whose output is bounded either by
1 their directive's precision or by a finite set of string
1 literals, are assumed to take on the value within the
1 range that results in the most bytes on output. For
1 example, the call to 'sprintf' below is diagnosed because
1 even with both A and B equal to zero, the terminating NUL
1 character (''\0'') appended by the function to the
1 destination buffer will be written past its end.
1 Increasing the size of the buffer by a single byte is
1 sufficient to avoid the warning, though it may not be
1 sufficient to avoid the overflow.
1
1 void f (int a, int b)
1 {
1 char buf [13];
1 sprintf (buf, "a = %i, b = %i\n", a, b);
1 }
1
1 '-Wformat-overflow=2'
1 Level 2 warns also about calls that might overflow the
1 destination buffer given an argument of sufficient length
1 or magnitude. At level 2, unknown numeric arguments are
1 assumed to have the minimum representable value for
1 signed types with a precision greater than 1, and the
1 maximum representable value otherwise. Unknown string
1 arguments whose length cannot be assumed to be bounded
1 either by the directive's precision, or by a finite set
1 of string literals they may evaluate to, or the character
1 array they may point to, are assumed to be 1 character
1 long.
1
1 At level 2, the call in the example above is again
1 diagnosed, but this time because with A equal to a 32-bit
1 'INT_MIN' the first '%i' directive will write some of its
1 digits beyond the end of the destination buffer. To make
1 the call safe regardless of the values of the two
1 variables, the size of the destination buffer must be
1 increased to at least 34 bytes. GCC includes the minimum
1 size of the buffer in an informational note following the
1 warning.
1
1 An alternative to increasing the size of the destination
1 buffer is to constrain the range of formatted values.
1 The maximum length of string arguments can be bounded by
1 specifying the precision in the format directive. When
1 numeric arguments of format directives can be assumed to
1 be bounded by less than the precision of their type,
1 choosing an appropriate length modifier to the format
1 specifier will reduce the required buffer size. For
1 example, if A and B in the example above can be assumed
1 to be within the precision of the 'short int' type then
1 using either the '%hi' format directive or casting the
1 argument to 'short' reduces the maximum required size of
1 the buffer to 24 bytes.
1
1 void f (int a, int b)
1 {
1 char buf [23];
1 sprintf (buf, "a = %hi, b = %i\n", a, (short)b);
1 }
1
1 '-Wno-format-zero-length'
1 If '-Wformat' is specified, do not warn about zero-length
1 formats. The C standard specifies that zero-length formats
1 are allowed.
1
1 '-Wformat=2'
1 Enable '-Wformat' plus additional format checks. Currently
1 equivalent to '-Wformat -Wformat-nonliteral -Wformat-security
1 -Wformat-y2k'.
1
1 '-Wformat-nonliteral'
1 If '-Wformat' is specified, also warn if the format string is
1 not a string literal and so cannot be checked, unless the
1 format function takes its format arguments as a 'va_list'.
1
1 '-Wformat-security'
1 If '-Wformat' is specified, also warn about uses of format
1 functions that represent possible security problems. At
1 present, this warns about calls to 'printf' and 'scanf'
1 functions where the format string is not a string literal and
1 there are no format arguments, as in 'printf (foo);'. This
1 may be a security hole if the format string came from
1 untrusted input and contains '%n'. (This is currently a
1 subset of what '-Wformat-nonliteral' warns about, but in
1 future warnings may be added to '-Wformat-security' that are
1 not included in '-Wformat-nonliteral'.)
1
1 '-Wformat-signedness'
1 If '-Wformat' is specified, also warn if the format string
1 requires an unsigned argument and the argument is signed and
1 vice versa.
1
1 '-Wformat-truncation'
1 '-Wformat-truncation=LEVEL'
1 Warn about calls to formatted input/output functions such as
1 'snprintf' and 'vsnprintf' that might result in output
1 truncation. When the exact number of bytes written by a
1 format directive cannot be determined at compile-time it is
1 estimated based on heuristics that depend on the LEVEL
1 argument and on optimization. While enabling optimization
1 will in most cases improve the accuracy of the warning, it may
1 also result in false positives. Except as noted otherwise,
1 the option uses the same logic '-Wformat-overflow'.
1
1 '-Wformat-truncation'
1 '-Wformat-truncation=1'
1 Level 1 of '-Wformat-truncation' enabled by '-Wformat'
1 employs a conservative approach that warns only about
1 calls to bounded functions whose return value is unused
1 and that will most likely result in output truncation.
1
1 '-Wformat-truncation=2'
1 Level 2 warns also about calls to bounded functions whose
1 return value is used and that might result in truncation
1 given an argument of sufficient length or magnitude.
1
1 '-Wformat-y2k'
1 If '-Wformat' is specified, also warn about 'strftime' formats
1 that may yield only a two-digit year.
1
1 '-Wnonnull'
1 Warn about passing a null pointer for arguments marked as requiring
1 a non-null value by the 'nonnull' function attribute.
1
1 '-Wnonnull' is included in '-Wall' and '-Wformat'. It can be
1 disabled with the '-Wno-nonnull' option.
1
1 '-Wnonnull-compare'
1 Warn when comparing an argument marked with the 'nonnull' function
1 attribute against null inside the function.
1
1 '-Wnonnull-compare' is included in '-Wall'. It can be disabled
1 with the '-Wno-nonnull-compare' option.
1
1 '-Wnull-dereference'
1 Warn if the compiler detects paths that trigger erroneous or
1 undefined behavior due to dereferencing a null pointer. This
1 option is only active when '-fdelete-null-pointer-checks' is
1 active, which is enabled by optimizations in most targets. The
1 precision of the warnings depends on the optimization options used.
1
1 '-Winit-self (C, C++, Objective-C and Objective-C++ only)'
1 Warn about uninitialized variables that are initialized with
1 themselves. Note this option can only be used with the
1 '-Wuninitialized' option.
1
1 For example, GCC warns about 'i' being uninitialized in the
1 following snippet only when '-Winit-self' has been specified:
1 int f()
1 {
1 int i = i;
1 return i;
1 }
1
1 This warning is enabled by '-Wall' in C++.
1
1 '-Wimplicit-int (C and Objective-C only)'
1 Warn when a declaration does not specify a type. This warning is
1 enabled by '-Wall'.
1
1 '-Wimplicit-function-declaration (C and Objective-C only)'
1 Give a warning whenever a function is used before being declared.
1 In C99 mode ('-std=c99' or '-std=gnu99'), this warning is enabled
1 by default and it is made into an error by '-pedantic-errors'.
1 This warning is also enabled by '-Wall'.
1
1 '-Wimplicit (C and Objective-C only)'
1 Same as '-Wimplicit-int' and '-Wimplicit-function-declaration'.
1 This warning is enabled by '-Wall'.
1
1 '-Wimplicit-fallthrough'
1 '-Wimplicit-fallthrough' is the same as '-Wimplicit-fallthrough=3'
1 and '-Wno-implicit-fallthrough' is the same as
1 '-Wimplicit-fallthrough=0'.
1
1 '-Wimplicit-fallthrough=N'
1 Warn when a switch case falls through. For example:
1
1 switch (cond)
1 {
1 case 1:
1 a = 1;
1 break;
1 case 2:
1 a = 2;
1 case 3:
1 a = 3;
1 break;
1 }
1
1 This warning does not warn when the last statement of a case cannot
1 fall through, e.g. when there is a return statement or a call to
1 function declared with the noreturn attribute.
1 '-Wimplicit-fallthrough=' also takes into account control flow
1 statements, such as ifs, and only warns when appropriate. E.g.
1
1 switch (cond)
1 {
1 case 1:
1 if (i > 3) {
1 bar (5);
1 break;
1 } else if (i < 1) {
1 bar (0);
1 } else
1 return;
1 default:
1 ...
1 }
1
1 Since there are occasions where a switch case fall through is
1 desirable, GCC provides an attribute, '__attribute__
1 ((fallthrough))', that is to be used along with a null statement to
1 suppress this warning that would normally occur:
1
1 switch (cond)
1 {
1 case 1:
1 bar (0);
1 __attribute__ ((fallthrough));
1 default:
1 ...
1 }
1
1 C++17 provides a standard way to suppress the
1 '-Wimplicit-fallthrough' warning using '[[fallthrough]];' instead
1 of the GNU attribute. In C++11 or C++14 users can use
1 '[[gnu::fallthrough]];', which is a GNU extension. Instead of
1 these attributes, it is also possible to add a fallthrough comment
1 to silence the warning. The whole body of the C or C++ style
1 comment should match the given regular expressions listed below.
1 The option argument N specifies what kind of comments are accepted:
1
1 * '-Wimplicit-fallthrough=0' disables the warning altogether.
1
1 * '-Wimplicit-fallthrough=1' matches '.*' regular expression,
1 any comment is used as fallthrough comment.
1
1 * '-Wimplicit-fallthrough=2' case insensitively matches
1 '.*falls?[ \t-]*thr(ough|u).*' regular expression.
1
1 * '-Wimplicit-fallthrough=3' case sensitively matches one of the
1 following regular expressions:
1
1 * '-fallthrough'
1
1 * '@fallthrough@'
1
1 * 'lint -fallthrough[ \t]*'
1
1 * '[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
1 FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?'
1
1 * '[ \t.!]*(Else,? |Intentional(ly)? )?
1 Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?'
1
1 * '[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
1 fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?'
1
1 * '-Wimplicit-fallthrough=4' case sensitively matches one of the
1 following regular expressions:
1
1 * '-fallthrough'
1
1 * '@fallthrough@'
1
1 * 'lint -fallthrough[ \t]*'
1
1 * '[ \t]*FALLTHR(OUGH|U)[ \t]*'
1
1 * '-Wimplicit-fallthrough=5' doesn't recognize any comments as
1 fallthrough comments, only attributes disable the warning.
1
1 The comment needs to be followed after optional whitespace and
1 other comments by 'case' or 'default' keywords or by a user label
1 that precedes some 'case' or 'default' label.
1
1 switch (cond)
1 {
1 case 1:
1 bar (0);
1 /* FALLTHRU */
1 default:
1 ...
1 }
1
1 The '-Wimplicit-fallthrough=3' warning is enabled by '-Wextra'.
1
1 '-Wif-not-aligned (C, C++, Objective-C and Objective-C++ only)'
1 Control if warning triggered by the 'warn_if_not_aligned' attribute
1 should be issued. This is enabled by default. Use
1 '-Wno-if-not-aligned' to disable it.
1
1 '-Wignored-qualifiers (C and C++ only)'
1 Warn if the return type of a function has a type qualifier such as
1 'const'. For ISO C such a type qualifier has no effect, since the
1 value returned by a function is not an lvalue. For C++, the
1 warning is only emitted for scalar types or 'void'. ISO C
1 prohibits qualified 'void' return types on function definitions, so
1 such return types always receive a warning even without this
1 option.
1
1 This warning is also enabled by '-Wextra'.
1
1 '-Wignored-attributes (C and C++ only)'
1 Warn when an attribute is ignored. This is different from the
1 '-Wattributes' option in that it warns whenever the compiler
1 decides to drop an attribute, not that the attribute is either
1 unknown, used in a wrong place, etc. This warning is enabled by
1 default.
1
1 '-Wmain'
1 Warn if the type of 'main' is suspicious. 'main' should be a
1 function with external linkage, returning int, taking either zero
1 arguments, two, or three arguments of appropriate types. This
1 warning is enabled by default in C++ and is enabled by either
1 '-Wall' or '-Wpedantic'.
1
1 '-Wmisleading-indentation (C and C++ only)'
1 Warn when the indentation of the code does not reflect the block
1 structure. Specifically, a warning is issued for 'if', 'else',
1 'while', and 'for' clauses with a guarded statement that does not
1 use braces, followed by an unguarded statement with the same
1 indentation.
1
1 In the following example, the call to "bar" is misleadingly
1 indented as if it were guarded by the "if" conditional.
1
1 if (some_condition ())
1 foo ();
1 bar (); /* Gotcha: this is not guarded by the "if". */
1
1 In the case of mixed tabs and spaces, the warning uses the
1 '-ftabstop=' option to determine if the statements line up
1 (defaulting to 8).
1
1 The warning is not issued for code involving multiline preprocessor
1 logic such as the following example.
1
1 if (flagA)
1 foo (0);
1 #if SOME_CONDITION_THAT_DOES_NOT_HOLD
1 if (flagB)
1 #endif
1 foo (1);
1
1 The warning is not issued after a '#line' directive, since this
1 typically indicates autogenerated code, and no assumptions can be
1 made about the layout of the file that the directive references.
1
1 This warning is enabled by '-Wall' in C and C++.
1
1 '-Wmissing-attributes'
1 Warn when a declaration of a function is missing one or more
1 attributes that a related function is declared with and whose
1 absence may adversely affect the correctness or efficiency of
1 generated code. For example, in C++, the warning is issued when an
1 explicit specialization of a primary template declared with
1 attribute 'alloc_align', 'alloc_size', 'assume_aligned', 'format',
1 'format_arg', 'malloc', or 'nonnull' is declared without it.
1 Attributes 'deprecated', 'error', and 'warning' suppress the
1 warning. (⇒Function Attributes).
1
1 '-Wmissing-attributes' is enabled by '-Wall'.
1
1 For example, since the declaration of the primary function template
1 below makes use of both attribute 'malloc' and 'alloc_size' the
1 declaration of the explicit specialization of the template is
1 diagnosed because it is missing one of the attributes.
1
1 template <class T>
1 T* __attribute__ ((malloc, alloc_size (1)))
1 allocate (size_t);
1
1 template <>
1 void* __attribute__ ((malloc)) // missing alloc_size
1 allocate<void> (size_t);
1
1 '-Wmissing-braces'
1 Warn if an aggregate or union initializer is not fully bracketed.
1 In the following example, the initializer for 'a' is not fully
1 bracketed, but that for 'b' is fully bracketed. This warning is
1 enabled by '-Wall' in C.
1
1 int a[2][2] = { 0, 1, 2, 3 };
1 int b[2][2] = { { 0, 1 }, { 2, 3 } };
1
1 This warning is enabled by '-Wall'.
1
1 '-Wmissing-include-dirs (C, C++, Objective-C and Objective-C++ only)'
1 Warn if a user-supplied include directory does not exist.
1
1 '-Wmultistatement-macros'
1 Warn about unsafe multiple statement macros that appear to be
1 guarded by a clause such as 'if', 'else', 'for', 'switch', or
1 'while', in which only the first statement is actually guarded
1 after the macro is expanded.
1
1 For example:
1
1 #define DOIT x++; y++
1 if (c)
1 DOIT;
1
1 will increment 'y' unconditionally, not just when 'c' holds. The
1 can usually be fixed by wrapping the macro in a do-while loop:
1 #define DOIT do { x++; y++; } while (0)
1 if (c)
1 DOIT;
1
1 This warning is enabled by '-Wall' in C and C++.
1
1 '-Wparentheses'
1 Warn if parentheses are omitted in certain contexts, such as when
1 there is an assignment in a context where a truth value is
1 expected, or when operators are nested whose precedence people
1 often get confused about.
1
1 Also warn if a comparison like 'x<=y<=z' appears; this is
1 equivalent to '(x<=y ? 1 : 0) <= z', which is a different
1 interpretation from that of ordinary mathematical notation.
1
1 Also warn for dangerous uses of the GNU extension to '?:' with
1 omitted middle operand. When the condition in the '?': operator is
1 a boolean expression, the omitted value is always 1. Often
1 programmers expect it to be a value computed inside the conditional
1 expression instead.
1
1 For C++ this also warns for some cases of unnecessary parentheses
1 in declarations, which can indicate an attempt at a function call
1 instead of a declaration:
1 {
1 // Declares a local variable called mymutex.
1 std::unique_lock<std::mutex> (mymutex);
1 // User meant std::unique_lock<std::mutex> lock (mymutex);
1 }
1
1 This warning is enabled by '-Wall'.
1
1 '-Wsequence-point'
1 Warn about code that may have undefined semantics because of
1 violations of sequence point rules in the C and C++ standards.
1
1 The C and C++ standards define the order in which expressions in a
1 C/C++ program are evaluated in terms of "sequence points", which
1 represent a partial ordering between the execution of parts of the
1 program: those executed before the sequence point, and those
1 executed after it. These occur after the evaluation of a full
1 expression (one which is not part of a larger expression), after
1 the evaluation of the first operand of a '&&', '||', '? :' or ','
1 (comma) operator, before a function is called (but after the
1 evaluation of its arguments and the expression denoting the called
1 function), and in certain other places. Other than as expressed by
1 the sequence point rules, the order of evaluation of subexpressions
1 of an expression is not specified. All these rules describe only a
1 partial order rather than a total order, since, for example, if two
1 functions are called within one expression with no sequence point
1 between them, the order in which the functions are called is not
1 specified. However, the standards committee have ruled that
1 function calls do not overlap.
1
1 It is not specified when between sequence points modifications to
1 the values of objects take effect. Programs whose behavior depends
1 on this have undefined behavior; the C and C++ standards specify
1 that "Between the previous and next sequence point an object shall
1 have its stored value modified at most once by the evaluation of an
1 expression. Furthermore, the prior value shall be read only to
1 determine the value to be stored.". If a program breaks these
1 rules, the results on any particular implementation are entirely
1 unpredictable.
1
1 Examples of code with undefined behavior are 'a = a++;', 'a[n] =
1 b[n++]' and 'a[i++] = i;'. Some more complicated cases are not
1 diagnosed by this option, and it may give an occasional false
1 positive result, but in general it has been found fairly effective
1 at detecting this sort of problem in programs.
1
1 The C++17 standard will define the order of evaluation of operands
1 in more cases: in particular it requires that the right-hand side
1 of an assignment be evaluated before the left-hand side, so the
1 above examples are no longer undefined. But this warning will
1 still warn about them, to help people avoid writing code that is
1 undefined in C and earlier revisions of C++.
1
1 The standard is worded confusingly, therefore there is some debate
1 over the precise meaning of the sequence point rules in subtle
1 cases. Links to discussions of the problem, including proposed
1 formal definitions, may be found on the GCC readings page, at
1 <http://gcc.gnu.org/readings.html>.
1
1 This warning is enabled by '-Wall' for C and C++.
1
1 '-Wno-return-local-addr'
1 Do not warn about returning a pointer (or in C++, a reference) to a
1 variable that goes out of scope after the function returns.
1
1 '-Wreturn-type'
1 Warn whenever a function is defined with a return type that
1 defaults to 'int'. Also warn about any 'return' statement with no
1 return value in a function whose return type is not 'void' (falling
1 off the end of the function body is considered returning without a
1 value).
1
1 For C only, warn about a 'return' statement with an expression in a
1 function whose return type is 'void', unless the expression type is
1 also 'void'. As a GNU extension, the latter case is accepted
1 without a warning unless '-Wpedantic' is used.
1
1 For C++, a function without return type always produces a
1 diagnostic message, even when '-Wno-return-type' is specified. The
1 only exceptions are 'main' and functions defined in system headers.
1
1 This warning is enabled by default for C++ and is enabled by
1 '-Wall'.
1
1 '-Wshift-count-negative'
1 Warn if shift count is negative. This warning is enabled by
1 default.
1
1 '-Wshift-count-overflow'
1 Warn if shift count >= width of type. This warning is enabled by
1 default.
1
1 '-Wshift-negative-value'
1 Warn if left shifting a negative value. This warning is enabled by
1 '-Wextra' in C99 and C++11 modes (and newer).
1
1 '-Wshift-overflow'
1 '-Wshift-overflow=N'
1 Warn about left shift overflows. This warning is enabled by
1 default in C99 and C++11 modes (and newer).
1
1 '-Wshift-overflow=1'
1 This is the warning level of '-Wshift-overflow' and is enabled
1 by default in C99 and C++11 modes (and newer). This warning
1 level does not warn about left-shifting 1 into the sign bit.
1 (However, in C, such an overflow is still rejected in contexts
1 where an integer constant expression is required.)
1
1 '-Wshift-overflow=2'
1 This warning level also warns about left-shifting 1 into the
1 sign bit, unless C++14 mode is active.
1
1 '-Wswitch'
1 Warn whenever a 'switch' statement has an index of enumerated type
1 and lacks a 'case' for one or more of the named codes of that
1 enumeration. (The presence of a 'default' label prevents this
1 warning.) 'case' labels outside the enumeration range also provoke
1 warnings when this option is used (even if there is a 'default'
1 label). This warning is enabled by '-Wall'.
1
1 '-Wswitch-default'
1 Warn whenever a 'switch' statement does not have a 'default' case.
1
1 '-Wswitch-enum'
1 Warn whenever a 'switch' statement has an index of enumerated type
1 and lacks a 'case' for one or more of the named codes of that
1 enumeration. 'case' labels outside the enumeration range also
1 provoke warnings when this option is used. The only difference
1 between '-Wswitch' and this option is that this option gives a
1 warning about an omitted enumeration code even if there is a
1 'default' label.
1
1 '-Wswitch-bool'
1 Warn whenever a 'switch' statement has an index of boolean type and
1 the case values are outside the range of a boolean type. It is
1 possible to suppress this warning by casting the controlling
1 expression to a type other than 'bool'. For example:
1 switch ((int) (a == 4))
1 {
1 ...
1 }
1 This warning is enabled by default for C and C++ programs.
1
1 '-Wswitch-unreachable'
1 Warn whenever a 'switch' statement contains statements between the
1 controlling expression and the first case label, which will never
1 be executed. For example:
1 switch (cond)
1 {
1 i = 15;
1 ...
1 case 5:
1 ...
1 }
1 '-Wswitch-unreachable' does not warn if the statement between the
1 controlling expression and the first case label is just a
1 declaration:
1 switch (cond)
1 {
1 int i;
1 ...
1 case 5:
1 i = 5;
1 ...
1 }
1 This warning is enabled by default for C and C++ programs.
1
1 '-Wsync-nand (C and C++ only)'
1 Warn when '__sync_fetch_and_nand' and '__sync_nand_and_fetch'
1 built-in functions are used. These functions changed semantics in
1 GCC 4.4.
1
1 '-Wunused-but-set-parameter'
1 Warn whenever a function parameter is assigned to, but otherwise
1 unused (aside from its declaration).
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 This warning is also enabled by '-Wunused' together with '-Wextra'.
1
1 '-Wunused-but-set-variable'
1 Warn whenever a local variable is assigned to, but otherwise unused
1 (aside from its declaration). This warning is enabled by '-Wall'.
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 This warning is also enabled by '-Wunused', which is enabled by
1 '-Wall'.
1
1 '-Wunused-function'
1 Warn whenever a static function is declared but not defined or a
1 non-inline static function is unused. This warning is enabled by
1 '-Wall'.
1
1 '-Wunused-label'
1 Warn whenever a label is declared but not used. This warning is
1 enabled by '-Wall'.
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 '-Wunused-local-typedefs (C, Objective-C, C++ and Objective-C++ only)'
1 Warn when a typedef locally defined in a function is not used.
1 This warning is enabled by '-Wall'.
1
1 '-Wunused-parameter'
1 Warn whenever a function parameter is unused aside from its
1 declaration.
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 '-Wno-unused-result'
1 Do not warn if a caller of a function marked with attribute
1 'warn_unused_result' (⇒Function Attributes) does not use its
1 return value. The default is '-Wunused-result'.
1
1 '-Wunused-variable'
1 Warn whenever a local or static variable is unused aside from its
1 declaration. This option implies '-Wunused-const-variable=1' for
1 C, but not for C++. This warning is enabled by '-Wall'.
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 '-Wunused-const-variable'
1 '-Wunused-const-variable=N'
1 Warn whenever a constant static variable is unused aside from its
1 declaration. '-Wunused-const-variable=1' is enabled by
1 '-Wunused-variable' for C, but not for C++. In C this declares
1 variable storage, but in C++ this is not an error since const
1 variables take the place of '#define's.
1
11 To suppress this warning use the 'unused' attribute (⇒Variable
Attributes).
1
1 '-Wunused-const-variable=1'
1 This is the warning level that is enabled by
1 '-Wunused-variable' for C. It warns only about unused static
1 const variables defined in the main compilation unit, but not
1 about static const variables declared in any header included.
1
1 '-Wunused-const-variable=2'
1 This warning level also warns for unused constant static
1 variables in headers (excluding system headers). This is the
1 warning level of '-Wunused-const-variable' and must be
1 explicitly requested since in C++ this isn't an error and in C
1 it might be harder to clean up all headers included.
1
1 '-Wunused-value'
1 Warn whenever a statement computes a result that is explicitly not
1 used. To suppress this warning cast the unused expression to
1 'void'. This includes an expression-statement or the left-hand
1 side of a comma expression that contains no side effects. For
1 example, an expression such as 'x[i,j]' causes a warning, while
1 'x[(void)i,j]' does not.
1
1 This warning is enabled by '-Wall'.
1
1 '-Wunused'
1 All the above '-Wunused' options combined.
1
1 In order to get a warning about an unused function parameter, you
1 must either specify '-Wextra -Wunused' (note that '-Wall' implies
1 '-Wunused'), or separately specify '-Wunused-parameter'.
1
1 '-Wuninitialized'
1 Warn if an automatic variable is used without first being
1 initialized or if a variable may be clobbered by a 'setjmp' call.
1 In C++, warn if a non-static reference or non-static 'const' member
1 appears in a class without constructors.
1
1 If you want to warn about code that uses the uninitialized value of
1 the variable in its own initializer, use the '-Winit-self' option.
1
1 These warnings occur for individual uninitialized or clobbered
1 elements of structure, union or array variables as well as for
1 variables that are uninitialized or clobbered as a whole. They do
1 not occur for variables or elements declared 'volatile'. Because
1 these warnings depend on optimization, the exact variables or
1 elements for which there are warnings depends on the precise
1 optimization options and version of GCC used.
1
1 Note that there may be no warning about a variable that is used
1 only to compute a value that itself is never used, because such
1 computations may be deleted by data flow analysis before the
1 warnings are printed.
1
1 '-Winvalid-memory-model'
DONTPRINTYET 1 Warn for invocations of ⇒__atomic Builtins, *note__sync
1DONTPRINTYET 1 Warn for invocations of ⇒__atomic Builtins, ⇒__sync
Builtins, and the C11 atomic generic functions with a memory
1 consistency argument that is either invalid for the operation or
1 outside the range of values of the 'memory_order' enumeration. For
1 example, since the '__atomic_store' and '__atomic_store_n'
1 built-ins are only defined for the relaxed, release, and
1 sequentially consistent memory orders the following code is
1 diagnosed:
1
1 void store (int *i)
1 {
1 __atomic_store_n (i, 0, memory_order_consume);
1 }
1
1 '-Winvalid-memory-model' is enabled by default.
1
1 '-Wmaybe-uninitialized'
1 For an automatic (i.e. local) variable, if there exists a path from
1 the function entry to a use of the variable that is initialized,
1 but there exist some other paths for which the variable is not
1 initialized, the compiler emits a warning if it cannot prove the
1 uninitialized paths are not executed at run time.
1
1 These warnings are only possible in optimizing compilation, because
1 otherwise GCC does not keep track of the state of variables.
1
1 These warnings are made optional because GCC may not be able to
1 determine when the code is correct in spite of appearing to have an
1 error. Here is one example of how this can happen:
1
1 {
1 int x;
1 switch (y)
1 {
1 case 1: x = 1;
1 break;
1 case 2: x = 4;
1 break;
1 case 3: x = 5;
1 }
1 foo (x);
1 }
1
1 If the value of 'y' is always 1, 2 or 3, then 'x' is always
1 initialized, but GCC doesn't know this. To suppress the warning,
1 you need to provide a default case with assert(0) or similar code.
1
1 This option also warns when a non-volatile automatic variable might
1 be changed by a call to 'longjmp'. The compiler sees only the
1 calls to 'setjmp'. It cannot know where 'longjmp' will be called;
1 in fact, a signal handler could call it at any point in the code.
1 As a result, you may get a warning even when there is in fact no
1 problem because 'longjmp' cannot in fact be called at the place
1 that would cause a problem.
1
1 Some spurious warnings can be avoided if you declare all the
11 functions you use that never return as 'noreturn'. ⇒Function
Attributes.
1
1 This warning is enabled by '-Wall' or '-Wextra'.
1
1 '-Wunknown-pragmas'
1 Warn when a '#pragma' directive is encountered that is not
1 understood by GCC. If this command-line option is used, warnings
1 are even issued for unknown pragmas in system header files. This
1 is not the case if the warnings are only enabled by the '-Wall'
1 command-line option.
1
1 '-Wno-pragmas'
1 Do not warn about misuses of pragmas, such as incorrect parameters,
1 invalid syntax, or conflicts between pragmas. See also
1 '-Wunknown-pragmas'.
1
1 '-Wstrict-aliasing'
1 This option is only active when '-fstrict-aliasing' is active. It
1 warns about code that might break the strict aliasing rules that
1 the compiler is using for optimization. The warning does not catch
1 all cases, but does attempt to catch the more common pitfalls. It
1 is included in '-Wall'. It is equivalent to '-Wstrict-aliasing=3'
1
1 '-Wstrict-aliasing=n'
1 This option is only active when '-fstrict-aliasing' is active. It
1 warns about code that might break the strict aliasing rules that
1 the compiler is using for optimization. Higher levels correspond
1 to higher accuracy (fewer false positives). Higher levels also
1 correspond to more effort, similar to the way '-O' works.
1 '-Wstrict-aliasing' is equivalent to '-Wstrict-aliasing=3'.
1
1 Level 1: Most aggressive, quick, least accurate. Possibly useful
1 when higher levels do not warn but '-fstrict-aliasing' still breaks
1 the code, as it has very few false negatives. However, it has many
1 false positives. Warns for all pointer conversions between
1 possibly incompatible types, even if never dereferenced. Runs in
1 the front end only.
1
1 Level 2: Aggressive, quick, not too precise. May still have many
1 false positives (not as many as level 1 though), and few false
1 negatives (but possibly more than level 1). Unlike level 1, it
1 only warns when an address is taken. Warns about incomplete types.
1 Runs in the front end only.
1
1 Level 3 (default for '-Wstrict-aliasing'): Should have very few
1 false positives and few false negatives. Slightly slower than
1 levels 1 or 2 when optimization is enabled. Takes care of the
1 common pun+dereference pattern in the front end:
1 '*(int*)&some_float'. If optimization is enabled, it also runs in
1 the back end, where it deals with multiple statement cases using
1 flow-sensitive points-to information. Only warns when the
1 converted pointer is dereferenced. Does not warn about incomplete
1 types.
1
1 '-Wstrict-overflow'
1 '-Wstrict-overflow=N'
1 This option is only active when signed overflow is undefined. It
1 warns about cases where the compiler optimizes based on the
1 assumption that signed overflow does not occur. Note that it does
1 not warn about all cases where the code might overflow: it only
1 warns about cases where the compiler implements some optimization.
1 Thus this warning depends on the optimization level.
1
1 An optimization that assumes that signed overflow does not occur is
1 perfectly safe if the values of the variables involved are such
1 that overflow never does, in fact, occur. Therefore this warning
1 can easily give a false positive: a warning about code that is not
1 actually a problem. To help focus on important issues, several
1 warning levels are defined. No warnings are issued for the use of
1 undefined signed overflow when estimating how many iterations a
1 loop requires, in particular when determining whether a loop will
1 be executed at all.
1
1 '-Wstrict-overflow=1'
1 Warn about cases that are both questionable and easy to avoid.
1 For example the compiler simplifies 'x + 1 > x' to '1'. This
1 level of '-Wstrict-overflow' is enabled by '-Wall'; higher
1 levels are not, and must be explicitly requested.
1
1 '-Wstrict-overflow=2'
1 Also warn about other cases where a comparison is simplified
1 to a constant. For example: 'abs (x) >= 0'. This can only be
1 simplified when signed integer overflow is undefined, because
1 'abs (INT_MIN)' overflows to 'INT_MIN', which is less than
1 zero. '-Wstrict-overflow' (with no level) is the same as
1 '-Wstrict-overflow=2'.
1
1 '-Wstrict-overflow=3'
1 Also warn about other cases where a comparison is simplified.
1 For example: 'x + 1 > 1' is simplified to 'x > 0'.
1
1 '-Wstrict-overflow=4'
1 Also warn about other simplifications not covered by the above
1 cases. For example: '(x * 10) / 5' is simplified to 'x * 2'.
1
1 '-Wstrict-overflow=5'
1 Also warn about cases where the compiler reduces the magnitude
1 of a constant involved in a comparison. For example: 'x + 2 >
1 y' is simplified to 'x + 1 >= y'. This is reported only at
1 the highest warning level because this simplification applies
1 to many comparisons, so this warning level gives a very large
1 number of false positives.
1
1 '-Wstringop-overflow'
1 '-Wstringop-overflow=TYPE'
1 Warn for calls to string manipulation functions such as 'memcpy'
1 and 'strcpy' that are determined to overflow the destination
1 buffer. The optional argument is one greater than the type of
1 Object Size Checking to perform to determine the size of the
1 destination. ⇒Object Size Checking. The argument is
1 meaningful only for functions that operate on character arrays but
1 not for raw memory functions like 'memcpy' which always make use of
1 Object Size type-0. The option also warns for calls that specify a
1 size in excess of the largest possible object or at most 'SIZE_MAX
1 / 2' bytes. The option produces the best results with optimization
1 enabled but can detect a small subset of simple buffer overflows
1 even without optimization in calls to the GCC built-in functions
1 like '__builtin_memcpy' that correspond to the standard functions.
1 In any case, the option warns about just a subset of buffer
1 overflows detected by the corresponding overflow checking
1 built-ins. For example, the option will issue a warning for the
1 'strcpy' call below because it copies at least 5 characters (the
1 string '"blue"' including the terminating NUL) into the buffer of
1 size 4.
1
1 enum Color { blue, purple, yellow };
1 const char* f (enum Color clr)
1 {
1 static char buf [4];
1 const char *str;
1 switch (clr)
1 {
1 case blue: str = "blue"; break;
1 case purple: str = "purple"; break;
1 case yellow: str = "yellow"; break;
1 }
1
1 return strcpy (buf, str); // warning here
1 }
1
1 Option '-Wstringop-overflow=2' is enabled by default.
1
1 '-Wstringop-overflow'
1 '-Wstringop-overflow=1'
1 The '-Wstringop-overflow=1' option uses type-zero Object Size
1 Checking to determine the sizes of destination objects. This
1 is the default setting of the option. At this setting the
1 option will not warn for writes past the end of subobjects of
1 larger objects accessed by pointers unless the size of the
1 largest surrounding object is known. When the destination may
1 be one of several objects it is assumed to be the largest one
1 of them. On Linux systems, when optimization is enabled at
1 this setting the option warns for the same code as when the
1 '_FORTIFY_SOURCE' macro is defined to a non-zero value.
1
1 '-Wstringop-overflow=2'
1 The '-Wstringop-overflow=2' option uses type-one Object Size
1 Checking to determine the sizes of destination objects. At
1 this setting the option will warn about overflows when writing
1 to members of the largest complete objects whose exact size is
1 known. It will, however, not warn for excessive writes to the
1 same members of unknown objects referenced by pointers since
1 they may point to arrays containing unknown numbers of
1 elements.
1
1 '-Wstringop-overflow=3'
1 The '-Wstringop-overflow=3' option uses type-two Object Size
1 Checking to determine the sizes of destination objects. At
1 this setting the option warns about overflowing the smallest
1 object or data member. This is the most restrictive setting
1 of the option that may result in warnings for safe code.
1
1 '-Wstringop-overflow=4'
1 The '-Wstringop-overflow=4' option uses type-three Object Size
1 Checking to determine the sizes of destination objects. At
1 this setting the option will warn about overflowing any data
1 members, and when the destination is one of several objects it
1 uses the size of the largest of them to decide whether to
1 issue a warning. Similarly to '-Wstringop-overflow=3' this
1 setting of the option may result in warnings for benign code.
1
1 '-Wstringop-truncation'
1 Warn for calls to bounded string manipulation functions such as
1 'strncat', 'strncpy', and 'stpncpy' that may either truncate the
1 copied string or leave the destination unchanged.
1
1 In the following example, the call to 'strncat' specifies a bound
1 that is less than the length of the source string. As a result,
1 the copy of the source will be truncated and so the call is
1 diagnosed. To avoid the warning use 'bufsize - strlen (buf) - 1)'
1 as the bound.
1
1 void append (char *buf, size_t bufsize)
1 {
1 strncat (buf, ".txt", 3);
1 }
1
1 As another example, the following call to 'strncpy' results in
1 copying to 'd' just the characters preceding the terminating NUL,
1 without appending the NUL to the end. Assuming the result of
1 'strncpy' is necessarily a NUL-terminated string is a common
1 mistake, and so the call is diagnosed. To avoid the warning when
1 the result is not expected to be NUL-terminated, call 'memcpy'
1 instead.
1
1 void copy (char *d, const char *s)
1 {
1 strncpy (d, s, strlen (s));
1 }
1
1 In the following example, the call to 'strncpy' specifies the size
1 of the destination buffer as the bound. If the length of the
1 source string is equal to or greater than this size the result of
1 the copy will not be NUL-terminated. Therefore, the call is also
1 diagnosed. To avoid the warning, specify 'sizeof buf - 1' as the
1 bound and set the last element of the buffer to 'NUL'.
1
1 void copy (const char *s)
1 {
1 char buf[80];
1 strncpy (buf, s, sizeof buf);
1 ...
1 }
1
1 In situations where a character array is intended to store a
1 sequence of bytes with no terminating 'NUL' such an array may be
1 annotated with attribute 'nonstring' to avoid this warning. Such
1 arrays, however, are not suitable arguments to functions that
1 expect 'NUL'-terminated strings. To help detect accidental misuses
1 of such arrays GCC issues warnings unless it can prove that the use
1 is safe. ⇒Common Variable Attributes.
1
1 Option '-Wstringop-truncation' is enabled by '-Wall'.
1
1 '-Wsuggest-attribute=[pure|const|noreturn|format|cold|malloc]'
1 Warn for cases where adding an attribute may be beneficial. The
1 attributes currently supported are listed below.
1
1 '-Wsuggest-attribute=pure'
1 '-Wsuggest-attribute=const'
1 '-Wsuggest-attribute=noreturn'
1 '-Wsuggest-attribute=malloc'
1
1 Warn about functions that might be candidates for attributes
1 'pure', 'const' or 'noreturn' or 'malloc'. The compiler only
1 warns for functions visible in other compilation units or (in
1 the case of 'pure' and 'const') if it cannot prove that the
1 function returns normally. A function returns normally if it
1 doesn't contain an infinite loop or return abnormally by
1 throwing, calling 'abort' or trapping. This analysis requires
1 option '-fipa-pure-const', which is enabled by default at '-O'
1 and higher. Higher optimization levels improve the accuracy
1 of the analysis.
1
1 '-Wsuggest-attribute=format'
1 '-Wmissing-format-attribute'
1
1 Warn about function pointers that might be candidates for
1 'format' attributes. Note these are only possible candidates,
1 not absolute ones. GCC guesses that function pointers with
1 'format' attributes that are used in assignment,
1 initialization, parameter passing or return statements should
1 have a corresponding 'format' attribute in the resulting type.
1 I.e. the left-hand side of the assignment or initialization,
1 the type of the parameter variable, or the return type of the
1 containing function respectively should also have a 'format'
1 attribute to avoid the warning.
1
1 GCC also warns about function definitions that might be
1 candidates for 'format' attributes. Again, these are only
1 possible candidates. GCC guesses that 'format' attributes
1 might be appropriate for any function that calls a function
1 like 'vprintf' or 'vscanf', but this might not always be the
1 case, and some functions for which 'format' attributes are
1 appropriate may not be detected.
1
1 '-Wsuggest-attribute=cold'
1
1 Warn about functions that might be candidates for 'cold'
1 attribute. This is based on static detection and generally
1 will only warn about functions which always leads to a call to
1 another 'cold' function such as wrappers of C++ 'throw' or
1 fatal error reporting functions leading to 'abort'.
1
1 '-Wsuggest-final-types'
1 Warn about types with virtual methods where code quality would be
1 improved if the type were declared with the C++11 'final'
1 specifier, or, if possible, declared in an anonymous namespace.
1 This allows GCC to more aggressively devirtualize the polymorphic
1 calls. This warning is more effective with link time optimization,
1 where the information about the class hierarchy graph is more
1 complete.
1
1 '-Wsuggest-final-methods'
1 Warn about virtual methods where code quality would be improved if
1 the method were declared with the C++11 'final' specifier, or, if
1 possible, its type were declared in an anonymous namespace or with
1 the 'final' specifier. This warning is more effective with
1 link-time optimization, where the information about the class
1 hierarchy graph is more complete. It is recommended to first
1 consider suggestions of '-Wsuggest-final-types' and then rebuild
1 with new annotations.
1
1 '-Wsuggest-override'
1 Warn about overriding virtual functions that are not marked with
1 the override keyword.
1
1 '-Walloc-zero'
1 Warn about calls to allocation functions decorated with attribute
1 'alloc_size' that specify zero bytes, including those to the
1 built-in forms of the functions 'aligned_alloc', 'alloca',
1 'calloc', 'malloc', and 'realloc'. Because the behavior of these
1 functions when called with a zero size differs among
1 implementations (and in the case of 'realloc' has been deprecated)
1 relying on it may result in subtle portability bugs and should be
1 avoided.
1
1 '-Walloc-size-larger-than=N'
1 Warn about calls to functions decorated with attribute 'alloc_size'
1 that attempt to allocate objects larger than the specified number
1 of bytes, or where the result of the size computation in an integer
1 type with infinite precision would exceed 'SIZE_MAX / 2'. The
1 option argument N may end in one of the standard suffixes
1 designating a multiple of bytes such as 'kB' and 'KiB' for kilobyte
1 and kibibyte, respectively, 'MB' and 'MiB' for megabyte and
1 mebibyte, and so on. '-Walloc-size-larger-than='PTRDIFF_MAX is
1 enabled by default. Warnings controlled by the option can be
11 disabled by specifying N of SIZE_MAX or more. ⇒Function
Attributes.
1
1 '-Walloca'
1 This option warns on all uses of 'alloca' in the source.
1
1 '-Walloca-larger-than=N'
1 This option warns on calls to 'alloca' that are not bounded by a
1 controlling predicate limiting its argument of integer type to at
1 most N bytes, or calls to 'alloca' where the bound is unknown.
1 Arguments of non-integer types are considered unbounded even if
1 they appear to be constrained to the expected range.
1
1 For example, a bounded case of 'alloca' could be:
1
1 void func (size_t n)
1 {
1 void *p;
1 if (n <= 1000)
1 p = alloca (n);
1 else
1 p = malloc (n);
1 f (p);
1 }
1
1 In the above example, passing '-Walloca-larger-than=1000' would not
1 issue a warning because the call to 'alloca' is known to be at most
1 1000 bytes. However, if '-Walloca-larger-than=500' were passed,
1 the compiler would emit a warning.
1
1 Unbounded uses, on the other hand, are uses of 'alloca' with no
1 controlling predicate constraining its integer argument. For
1 example:
1
1 void func ()
1 {
1 void *p = alloca (n);
1 f (p);
1 }
1
1 If '-Walloca-larger-than=500' were passed, the above would trigger
1 a warning, but this time because of the lack of bounds checking.
1
1 Note, that even seemingly correct code involving signed integers
1 could cause a warning:
1
1 void func (signed int n)
1 {
1 if (n < 500)
1 {
1 p = alloca (n);
1 f (p);
1 }
1 }
1
1 In the above example, N could be negative, causing a larger than
1 expected argument to be implicitly cast into the 'alloca' call.
1
1 This option also warns when 'alloca' is used in a loop.
1
1 This warning is not enabled by '-Wall', and is only active when
1 '-ftree-vrp' is active (default for '-O2' and above).
1
1 See also '-Wvla-larger-than=N'.
1
1 '-Warray-bounds'
1 '-Warray-bounds=N'
1 This option is only active when '-ftree-vrp' is active (default for
1 '-O2' and above). It warns about subscripts to arrays that are
1 always out of bounds. This warning is enabled by '-Wall'.
1
1 '-Warray-bounds=1'
1 This is the warning level of '-Warray-bounds' and is enabled
1 by '-Wall'; higher levels are not, and must be explicitly
1 requested.
1
1 '-Warray-bounds=2'
1 This warning level also warns about out of bounds access for
1 arrays at the end of a struct and for arrays accessed through
1 pointers. This warning level may give a larger number of
1 false positives and is deactivated by default.
1
1 '-Wattribute-alias'
1 Warn about declarations using the 'alias' and similar attributes
11 whose target is incompatible with the type of the alias. ⇒
Declaring Attributes of Functions Function Attributes.
1
1 '-Wbidi-chars=[none|unpaired|any]'
1 Warn about possibly misleading UTF-8 bidirectional control
1 characters in comments, string literals, character constants, and
1 identifiers. Such characters can change left-to-right writing
1 direction into right-to-left (and vice versa), which can cause
1 confusion between the logical order and visual order. This may be
1 dangerous; for instance, it may seem that a piece of code is not
1 commented out, whereas it in fact is.
1
1 There are three levels of warning supported by GCC. The default is
1 '-Wbidi-chars=unpaired', which warns about improperly terminated
1 bidi contexts. '-Wbidi-chars=none' turns the warning off.
1 '-Wbidi-chars=any' warns about any use of bidirectional control
1 characters.
1
1 '-Wbool-compare'
1 Warn about boolean expression compared with an integer value
1 different from 'true'/'false'. For instance, the following
1 comparison is always false:
1 int n = 5;
1 ...
1 if ((n > 1) == 2) { ... }
1 This warning is enabled by '-Wall'.
1
1 '-Wbool-operation'
1 Warn about suspicious operations on expressions of a boolean type.
1 For instance, bitwise negation of a boolean is very likely a bug in
1 the program. For C, this warning also warns about incrementing or
1 decrementing a boolean, which rarely makes sense. (In C++,
1 decrementing a boolean is always invalid. Incrementing a boolean
1 is invalid in C++17, and deprecated otherwise.)
1
1 This warning is enabled by '-Wall'.
1
1 '-Wduplicated-branches'
1 Warn when an if-else has identical branches. This warning detects
1 cases like
1 if (p != NULL)
1 return 0;
1 else
1 return 0;
1 It doesn't warn when both branches contain just a null statement.
1 This warning also warn for conditional operators:
1 int i = x ? *p : *p;
1
1 '-Wduplicated-cond'
1 Warn about duplicated conditions in an if-else-if chain. For
1 instance, warn for the following code:
1 if (p->q != NULL) { ... }
1 else if (p->q != NULL) { ... }
1
1 '-Wframe-address'
1 Warn when the '__builtin_frame_address' or
1 '__builtin_return_address' is called with an argument greater than
1 0. Such calls may return indeterminate values or crash the
1 program. The warning is included in '-Wall'.
1
1 '-Wno-discarded-qualifiers (C and Objective-C only)'
1 Do not warn if type qualifiers on pointers are being discarded.
1 Typically, the compiler warns if a 'const char *' variable is
1 passed to a function that takes a 'char *' parameter. This option
1 can be used to suppress such a warning.
1
1 '-Wno-discarded-array-qualifiers (C and Objective-C only)'
1 Do not warn if type qualifiers on arrays which are pointer targets
1 are being discarded. Typically, the compiler warns if a 'const int
1 (*)[]' variable is passed to a function that takes a 'int (*)[]'
1 parameter. This option can be used to suppress such a warning.
1
1 '-Wno-incompatible-pointer-types (C and Objective-C only)'
1 Do not warn when there is a conversion between pointers that have
1 incompatible types. This warning is for cases not covered by
1 '-Wno-pointer-sign', which warns for pointer argument passing or
1 assignment with different signedness.
1
1 '-Wno-int-conversion (C and Objective-C only)'
1 Do not warn about incompatible integer to pointer and pointer to
1 integer conversions. This warning is about implicit conversions;
1 for explicit conversions the warnings '-Wno-int-to-pointer-cast'
1 and '-Wno-pointer-to-int-cast' may be used.
1
1 '-Wno-div-by-zero'
1 Do not warn about compile-time integer division by zero.
1 Floating-point division by zero is not warned about, as it can be a
1 legitimate way of obtaining infinities and NaNs.
1
1 '-Wsystem-headers'
1 Print warning messages for constructs found in system header files.
1 Warnings from system headers are normally suppressed, on the
1 assumption that they usually do not indicate real problems and
1 would only make the compiler output harder to read. Using this
1 command-line option tells GCC to emit warnings from system headers
1 as if they occurred in user code. However, note that using '-Wall'
1 in conjunction with this option does _not_ warn about unknown
1 pragmas in system headers--for that, '-Wunknown-pragmas' must also
1 be used.
1
1 '-Wtautological-compare'
1 Warn if a self-comparison always evaluates to true or false. This
1 warning detects various mistakes such as:
1 int i = 1;
1 ...
1 if (i > i) { ... }
1
1 This warning also warns about bitwise comparisons that always
1 evaluate to true or false, for instance:
1 if ((a & 16) == 10) { ... }
1 will always be false.
1
1 This warning is enabled by '-Wall'.
1
1 '-Wtrampolines'
1 Warn about trampolines generated for pointers to nested functions.
1 A trampoline is a small piece of data or code that is created at
1 run time on the stack when the address of a nested function is
1 taken, and is used to call the nested function indirectly. For
1 some targets, it is made up of data only and thus requires no
1 special treatment. But, for most targets, it is made up of code
1 and thus requires the stack to be made executable in order for the
1 program to work properly.
1
1 '-Wfloat-equal'
1 Warn if floating-point values are used in equality comparisons.
1
1 The idea behind this is that sometimes it is convenient (for the
1 programmer) to consider floating-point values as approximations to
1 infinitely precise real numbers. If you are doing this, then you
1 need to compute (by analyzing the code, or in some other way) the
1 maximum or likely maximum error that the computation introduces,
1 and allow for it when performing comparisons (and when producing
1 output, but that's a different problem). In particular, instead of
1 testing for equality, you should check to see whether the two
1 values have ranges that overlap; and this is done with the
1 relational operators, so equality comparisons are probably
1 mistaken.
1
1 '-Wtraditional (C and Objective-C only)'
1 Warn about certain constructs that behave differently in
1 traditional and ISO C. Also warn about ISO C constructs that have
1 no traditional C equivalent, and/or problematic constructs that
1 should be avoided.
1
1 * Macro parameters that appear within string literals in the
1 macro body. In traditional C macro replacement takes place
1 within string literals, but in ISO C it does not.
1
1 * In traditional C, some preprocessor directives did not exist.
1 Traditional preprocessors only considered a line to be a
1 directive if the '#' appeared in column 1 on the line.
1 Therefore '-Wtraditional' warns about directives that
1 traditional C understands but ignores because the '#' does not
1 appear as the first character on the line. It also suggests
1 you hide directives like '#pragma' not understood by
1 traditional C by indenting them. Some traditional
1 implementations do not recognize '#elif', so this option
1 suggests avoiding it altogether.
1
1 * A function-like macro that appears without arguments.
1
1 * The unary plus operator.
1
1 * The 'U' integer constant suffix, or the 'F' or 'L'
1 floating-point constant suffixes. (Traditional C does support
1 the 'L' suffix on integer constants.) Note, these suffixes
1 appear in macros defined in the system headers of most modern
1 systems, e.g. the '_MIN'/'_MAX' macros in '<limits.h>'. Use
1 of these macros in user code might normally lead to spurious
1 warnings, however GCC's integrated preprocessor has enough
1 context to avoid warning in these cases.
1
1 * A function declared external in one block and then used after
1 the end of the block.
1
1 * A 'switch' statement has an operand of type 'long'.
1
1 * A non-'static' function declaration follows a 'static' one.
1 This construct is not accepted by some traditional C
1 compilers.
1
1 * The ISO type of an integer constant has a different width or
1 signedness from its traditional type. This warning is only
1 issued if the base of the constant is ten. I.e. hexadecimal
1 or octal values, which typically represent bit patterns, are
1 not warned about.
1
1 * Usage of ISO string concatenation is detected.
1
1 * Initialization of automatic aggregates.
1
1 * Identifier conflicts with labels. Traditional C lacks a
1 separate namespace for labels.
1
1 * Initialization of unions. If the initializer is zero, the
1 warning is omitted. This is done under the assumption that
1 the zero initializer in user code appears conditioned on e.g.
1 '__STDC__' to avoid missing initializer warnings and relies on
1 default initialization to zero in the traditional C case.
1
1 * Conversions by prototypes between fixed/floating-point values
1 and vice versa. The absence of these prototypes when
1 compiling with traditional C causes serious problems. This is
1 a subset of the possible conversion warnings; for the full set
1 use '-Wtraditional-conversion'.
1
1 * Use of ISO C style function definitions. This warning
1 intentionally is _not_ issued for prototype declarations or
1 variadic functions because these ISO C features appear in your
1 code when using libiberty's traditional C compatibility
1 macros, 'PARAMS' and 'VPARAMS'. This warning is also bypassed
1 for nested functions because that feature is already a GCC
1 extension and thus not relevant to traditional C
1 compatibility.
1
1 '-Wtraditional-conversion (C and Objective-C only)'
1 Warn if a prototype causes a type conversion that is different from
1 what would happen to the same argument in the absence of a
1 prototype. This includes conversions of fixed point to floating
1 and vice versa, and conversions changing the width or signedness of
1 a fixed-point argument except when the same as the default
1 promotion.
1
1 '-Wdeclaration-after-statement (C and Objective-C only)'
1 Warn when a declaration is found after a statement in a block.
1 This construct, known from C++, was introduced with ISO C99 and is
11 by default allowed in GCC. It is not supported by ISO C90. ⇒
Mixed Declarations.
1
1 '-Wshadow'
1 Warn whenever a local variable or type declaration shadows another
1 variable, parameter, type, class member (in C++), or instance
1 variable (in Objective-C) or whenever a built-in function is
1 shadowed. Note that in C++, the compiler warns if a local variable
1 shadows an explicit typedef, but not if it shadows a
1 struct/class/enum. Same as '-Wshadow=global'.
1
1 '-Wno-shadow-ivar (Objective-C only)'
1 Do not warn whenever a local variable shadows an instance variable
1 in an Objective-C method.
1
1 '-Wshadow=global'
1 The default for '-Wshadow'. Warns for any (global) shadowing.
1
1 '-Wshadow=local'
1 Warn when a local variable shadows another local variable or
1 parameter. This warning is enabled by '-Wshadow=global'.
1
1 '-Wshadow=compatible-local'
1 Warn when a local variable shadows another local variable or
1 parameter whose type is compatible with that of the shadowing
1 variable. In C++, type compatibility here means the type of the
1 shadowing variable can be converted to that of the shadowed
1 variable. The creation of this flag (in addition to
1 '-Wshadow=local') is based on the idea that when a local variable
1 shadows another one of incompatible type, it is most likely
1 intentional, not a bug or typo, as shown in the following example:
1
1 for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
1 {
1 for (int i = 0; i < N; ++i)
1 {
1 ...
1 }
1 ...
1 }
1
1 Since the two variable 'i' in the example above have incompatible
1 types, enabling only '-Wshadow=compatible-local' will not emit a
1 warning. Because their types are incompatible, if a programmer
1 accidentally uses one in place of the other, type checking will
1 catch that and emit an error or warning. So not warning (about
1 shadowing) in this case will not lead to undetected bugs. Use of
1 this flag instead of '-Wshadow=local' can possibly reduce the
1 number of warnings triggered by intentional shadowing.
1
1 This warning is enabled by '-Wshadow=local'.
1
1 '-Wlarger-than=LEN'
1 Warn whenever an object of larger than LEN bytes is defined.
1
1 '-Wframe-larger-than=LEN'
1 Warn if the size of a function frame is larger than LEN bytes. The
1 computation done to determine the stack frame size is approximate
1 and not conservative. The actual requirements may be somewhat
1 greater than LEN even if you do not get a warning. In addition,
1 any space allocated via 'alloca', variable-length arrays, or
1 related constructs is not included by the compiler when determining
1 whether or not to issue a warning.
1
1 '-Wno-free-nonheap-object'
1 Do not warn when attempting to free an object that was not
1 allocated on the heap.
1
1 '-Wstack-usage=LEN'
1 Warn if the stack usage of a function might be larger than LEN
1 bytes. The computation done to determine the stack usage is
1 conservative. Any space allocated via 'alloca', variable-length
1 arrays, or related constructs is included by the compiler when
1 determining whether or not to issue a warning.
1
1 The message is in keeping with the output of '-fstack-usage'.
1
1 * If the stack usage is fully static but exceeds the specified
1 amount, it's:
1
1 warning: stack usage is 1120 bytes
1 * If the stack usage is (partly) dynamic but bounded, it's:
1
1 warning: stack usage might be 1648 bytes
1 * If the stack usage is (partly) dynamic and not bounded, it's:
1
1 warning: stack usage might be unbounded
1
1 '-Wno-pedantic-ms-format (MinGW targets only)'
1 When used in combination with '-Wformat' and '-pedantic' without
1 GNU extensions, this option disables the warnings about non-ISO
1 'printf' / 'scanf' format width specifiers 'I32', 'I64', and 'I'
1 used on Windows targets, which depend on the MS runtime.
1
1 '-Waligned-new'
1 Warn about a new-expression of a type that requires greater
1 alignment than the 'alignof(std::max_align_t)' but uses an
1 allocation function without an explicit alignment parameter. This
1 option is enabled by '-Wall'.
1
1 Normally this only warns about global allocation functions, but
1 '-Waligned-new=all' also warns about class member allocation
1 functions.
1
1 '-Wplacement-new'
1 '-Wplacement-new=N'
1 Warn about placement new expressions with undefined behavior, such
1 as constructing an object in a buffer that is smaller than the type
1 of the object. For example, the placement new expression below is
1 diagnosed because it attempts to construct an array of 64 integers
1 in a buffer only 64 bytes large.
1 char buf [64];
1 new (buf) int[64];
1 This warning is enabled by default.
1
1 '-Wplacement-new=1'
1 This is the default warning level of '-Wplacement-new'. At
1 this level the warning is not issued for some strictly
1 undefined constructs that GCC allows as extensions for
1 compatibility with legacy code. For example, the following
1 'new' expression is not diagnosed at this level even though it
1 has undefined behavior according to the C++ standard because
1 it writes past the end of the one-element array.
1 struct S { int n, a[1]; };
1 S *s = (S *)malloc (sizeof *s + 31 * sizeof s->a[0]);
1 new (s->a)int [32]();
1
1 '-Wplacement-new=2'
1 At this level, in addition to diagnosing all the same
1 constructs as at level 1, a diagnostic is also issued for
1 placement new expressions that construct an object in the last
1 member of structure whose type is an array of a single element
1 and whose size is less than the size of the object being
1 constructed. While the previous example would be diagnosed,
1 the following construct makes use of the flexible member array
1 extension to avoid the warning at level 2.
1 struct S { int n, a[]; };
1 S *s = (S *)malloc (sizeof *s + 32 * sizeof s->a[0]);
1 new (s->a)int [32]();
1
1 '-Wpointer-arith'
1 Warn about anything that depends on the "size of" a function type
1 or of 'void'. GNU C assigns these types a size of 1, for
1 convenience in calculations with 'void *' pointers and pointers to
1 functions. In C++, warn also when an arithmetic operation involves
1 'NULL'. This warning is also enabled by '-Wpedantic'.
1
1 '-Wpointer-compare'
1 Warn if a pointer is compared with a zero character constant. This
1 usually means that the pointer was meant to be dereferenced. For
1 example:
1
1 const char *p = foo ();
1 if (p == '\0')
1 return 42;
1
1 Note that the code above is invalid in C++11.
1
1 This warning is enabled by default.
1
1 '-Wtype-limits'
1 Warn if a comparison is always true or always false due to the
1 limited range of the data type, but do not warn for constant
1 expressions. For example, warn if an unsigned variable is compared
1 against zero with '<' or '>='. This warning is also enabled by
1 '-Wextra'.
1
1 '-Wcomment'
1 '-Wcomments'
1 Warn whenever a comment-start sequence '/*' appears in a '/*'
1 comment, or whenever a backslash-newline appears in a '//' comment.
1 This warning is enabled by '-Wall'.
1
1 '-Wtrigraphs'
1 Warn if any trigraphs are encountered that might change the meaning
1 of the program. Trigraphs within comments are not warned about,
1 except those that would form escaped newlines.
1
1 This option is implied by '-Wall'. If '-Wall' is not given, this
1 option is still enabled unless trigraphs are enabled. To get
1 trigraph conversion without warnings, but get the other '-Wall'
1 warnings, use '-trigraphs -Wall -Wno-trigraphs'.
1
1 '-Wundef'
1 Warn if an undefined identifier is evaluated in an '#if' directive.
1 Such identifiers are replaced with zero.
1
1 '-Wexpansion-to-defined'
1 Warn whenever 'defined' is encountered in the expansion of a macro
1 (including the case where the macro is expanded by an '#if'
1 directive). Such usage is not portable. This warning is also
1 enabled by '-Wpedantic' and '-Wextra'.
1
1 '-Wunused-macros'
1 Warn about macros defined in the main file that are unused. A
1 macro is "used" if it is expanded or tested for existence at least
1 once. The preprocessor also warns if the macro has not been used
1 at the time it is redefined or undefined.
1
1 Built-in macros, macros defined on the command line, and macros
1 defined in include files are not warned about.
1
1 _Note:_ If a macro is actually used, but only used in skipped
1 conditional blocks, then the preprocessor reports it as unused. To
1 avoid the warning in such a case, you might improve the scope of
1 the macro's definition by, for example, moving it into the first
1 skipped block. Alternatively, you could provide a dummy use with
1 something like:
1
1 #if defined the_macro_causing_the_warning
1 #endif
1
1 '-Wno-endif-labels'
1 Do not warn whenever an '#else' or an '#endif' are followed by
1 text. This sometimes happens in older programs with code of the
1 form
1
1 #if FOO
1 ...
1 #else FOO
1 ...
1 #endif FOO
1
1 The second and third 'FOO' should be in comments. This warning is
1 on by default.
1
1 '-Wbad-function-cast (C and Objective-C only)'
1 Warn when a function call is cast to a non-matching type. For
1 example, warn if a call to a function returning an integer type is
1 cast to a pointer type.
1
1 '-Wc90-c99-compat (C and Objective-C only)'
1 Warn about features not present in ISO C90, but present in ISO C99.
1 For instance, warn about use of variable length arrays, 'long long'
1 type, 'bool' type, compound literals, designated initializers, and
1 so on. This option is independent of the standards mode. Warnings
1 are disabled in the expression that follows '__extension__'.
1
1 '-Wc99-c11-compat (C and Objective-C only)'
1 Warn about features not present in ISO C99, but present in ISO C11.
1 For instance, warn about use of anonymous structures and unions,
1 '_Atomic' type qualifier, '_Thread_local' storage-class specifier,
1 '_Alignas' specifier, 'Alignof' operator, '_Generic' keyword, and
1 so on. This option is independent of the standards mode. Warnings
1 are disabled in the expression that follows '__extension__'.
1
1 '-Wc++-compat (C and Objective-C only)'
1 Warn about ISO C constructs that are outside of the common subset
1 of ISO C and ISO C++, e.g. request for implicit conversion from
1 'void *' to a pointer to non-'void' type.
1
1 '-Wc++11-compat (C++ and Objective-C++ only)'
1 Warn about C++ constructs whose meaning differs between ISO C++
1 1998 and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are
1 keywords in ISO C++ 2011. This warning turns on '-Wnarrowing' and
1 is enabled by '-Wall'.
1
1 '-Wc++14-compat (C++ and Objective-C++ only)'
1 Warn about C++ constructs whose meaning differs between ISO C++
1 2011 and ISO C++ 2014. This warning is enabled by '-Wall'.
1
1 '-Wc++17-compat (C++ and Objective-C++ only)'
1 Warn about C++ constructs whose meaning differs between ISO C++
1 2014 and ISO C++ 2017. This warning is enabled by '-Wall'.
1
1 '-Wcast-qual'
1 Warn whenever a pointer is cast so as to remove a type qualifier
1 from the target type. For example, warn if a 'const char *' is
1 cast to an ordinary 'char *'.
1
1 Also warn when making a cast that introduces a type qualifier in an
1 unsafe way. For example, casting 'char **' to 'const char **' is
1 unsafe, as in this example:
1
1 /* p is char ** value. */
1 const char **q = (const char **) p;
1 /* Assignment of readonly string to const char * is OK. */
1 *q = "string";
1 /* Now char** pointer points to read-only memory. */
1 **p = 'b';
1
1 '-Wcast-align'
1 Warn whenever a pointer is cast such that the required alignment of
1 the target is increased. For example, warn if a 'char *' is cast
1 to an 'int *' on machines where integers can only be accessed at
1 two- or four-byte boundaries.
1
1 '-Wcast-align=strict'
1 Warn whenever a pointer is cast such that the required alignment of
1 the target is increased. For example, warn if a 'char *' is cast
1 to an 'int *' regardless of the target machine.
1
1 '-Wcast-function-type'
1 Warn when a function pointer is cast to an incompatible function
1 pointer. In a cast involving function types with a variable
1 argument list only the types of initial arguments that are provided
1 are considered. Any parameter of pointer-type matches any other
1 pointer-type. Any benign differences in integral types are
1 ignored, like 'int' vs. 'long' on ILP32 targets. Likewise type
1 qualifiers are ignored. The function type 'void (*) (void)' is
1 special and matches everything, which can be used to suppress this
1 warning. In a cast involving pointer to member types this warning
1 warns whenever the type cast is changing the pointer to member
1 type. This warning is enabled by '-Wextra'.
1
1 '-Wwrite-strings'
1 When compiling C, give string constants the type 'const
1 char[LENGTH]' so that copying the address of one into a non-'const'
1 'char *' pointer produces a warning. These warnings help you find
1 at compile time code that can try to write into a string constant,
1 but only if you have been very careful about using 'const' in
1 declarations and prototypes. Otherwise, it is just a nuisance.
1 This is why we did not make '-Wall' request these warnings.
1
1 When compiling C++, warn about the deprecated conversion from
1 string literals to 'char *'. This warning is enabled by default
1 for C++ programs.
1
1 '-Wcatch-value'
1 '-Wcatch-value=N (C++ and Objective-C++ only)'
1 Warn about catch handlers that do not catch via reference. With
1 '-Wcatch-value=1' (or '-Wcatch-value' for short) warn about
1 polymorphic class types that are caught by value. With
1 '-Wcatch-value=2' warn about all class types that are caught by
1 value. With '-Wcatch-value=3' warn about all types that are not
1 caught by reference. '-Wcatch-value' is enabled by '-Wall'.
1
1 '-Wclobbered'
1 Warn for variables that might be changed by 'longjmp' or 'vfork'.
1 This warning is also enabled by '-Wextra'.
1
1 '-Wconditionally-supported (C++ and Objective-C++ only)'
1 Warn for conditionally-supported (C++11 [intro.defs]) constructs.
1
1 '-Wconversion'
1 Warn for implicit conversions that may alter a value. This
1 includes conversions between real and integer, like 'abs (x)' when
1 'x' is 'double'; conversions between signed and unsigned, like
1 'unsigned ui = -1'; and conversions to smaller types, like 'sqrtf
1 (M_PI)'. Do not warn for explicit casts like 'abs ((int) x)' and
1 'ui = (unsigned) -1', or if the value is not changed by the
1 conversion like in 'abs (2.0)'. Warnings about conversions between
1 signed and unsigned integers can be disabled by using
1 '-Wno-sign-conversion'.
1
1 For C++, also warn for confusing overload resolution for
1 user-defined conversions; and conversions that never use a type
1 conversion operator: conversions to 'void', the same type, a base
1 class or a reference to them. Warnings about conversions between
1 signed and unsigned integers are disabled by default in C++ unless
1 '-Wsign-conversion' is explicitly enabled.
1
1 '-Wno-conversion-null (C++ and Objective-C++ only)'
1 Do not warn for conversions between 'NULL' and non-pointer types.
1 '-Wconversion-null' is enabled by default.
1
1 '-Wzero-as-null-pointer-constant (C++ and Objective-C++ only)'
1 Warn when a literal '0' is used as null pointer constant. This can
1 be useful to facilitate the conversion to 'nullptr' in C++11.
1
1 '-Wsubobject-linkage (C++ and Objective-C++ only)'
1 Warn if a class type has a base or a field whose type uses the
1 anonymous namespace or depends on a type with no linkage. If a
1 type A depends on a type B with no or internal linkage, defining it
1 in multiple translation units would be an ODR violation because the
1 meaning of B is different in each translation unit. If A only
1 appears in a single translation unit, the best way to silence the
1 warning is to give it internal linkage by putting it in an
1 anonymous namespace as well. The compiler doesn't give this
1 warning for types defined in the main .C file, as those are
1 unlikely to have multiple definitions. '-Wsubobject-linkage' is
1 enabled by default.
1
1 '-Wdangling-else'
1 Warn about constructions where there may be confusion to which 'if'
1 statement an 'else' branch belongs. Here is an example of such a
1 case:
1
1 {
1 if (a)
1 if (b)
1 foo ();
1 else
1 bar ();
1 }
1
1 In C/C++, every 'else' branch belongs to the innermost possible
1 'if' statement, which in this example is 'if (b)'. This is often
1 not what the programmer expected, as illustrated in the above
1 example by indentation the programmer chose. When there is the
1 potential for this confusion, GCC issues a warning when this flag
1 is specified. To eliminate the warning, add explicit braces around
1 the innermost 'if' statement so there is no way the 'else' can
1 belong to the enclosing 'if'. The resulting code looks like this:
1
1 {
1 if (a)
1 {
1 if (b)
1 foo ();
1 else
1 bar ();
1 }
1 }
1
1 This warning is enabled by '-Wparentheses'.
1
1 '-Wdate-time'
1 Warn when macros '__TIME__', '__DATE__' or '__TIMESTAMP__' are
1 encountered as they might prevent bit-wise-identical reproducible
1 compilations.
1
1 '-Wdelete-incomplete (C++ and Objective-C++ only)'
1 Warn when deleting a pointer to incomplete type, which may cause
1 undefined behavior at runtime. This warning is enabled by default.
1
1 '-Wuseless-cast (C++ and Objective-C++ only)'
1 Warn when an expression is casted to its own type.
1
1 '-Wempty-body'
1 Warn if an empty body occurs in an 'if', 'else' or 'do while'
1 statement. This warning is also enabled by '-Wextra'.
1
1 '-Wenum-compare'
1 Warn about a comparison between values of different enumerated
1 types. In C++ enumerated type mismatches in conditional
1 expressions are also diagnosed and the warning is enabled by
1 default. In C this warning is enabled by '-Wall'.
1
1 '-Wextra-semi (C++, Objective-C++ only)'
1 Warn about redundant semicolon after in-class function definition.
1
1 '-Wjump-misses-init (C, Objective-C only)'
1 Warn if a 'goto' statement or a 'switch' statement jumps forward
1 across the initialization of a variable, or jumps backward to a
1 label after the variable has been initialized. This only warns
1 about variables that are initialized when they are declared. This
1 warning is only supported for C and Objective-C; in C++ this sort
1 of branch is an error in any case.
1
1 '-Wjump-misses-init' is included in '-Wc++-compat'. It can be
1 disabled with the '-Wno-jump-misses-init' option.
1
1 '-Wsign-compare'
1 Warn when a comparison between signed and unsigned values could
1 produce an incorrect result when the signed value is converted to
1 unsigned. In C++, this warning is also enabled by '-Wall'. In C,
1 it is also enabled by '-Wextra'.
1
1 '-Wsign-conversion'
1 Warn for implicit conversions that may change the sign of an
1 integer value, like assigning a signed integer expression to an
1 unsigned integer variable. An explicit cast silences the warning.
1 In C, this option is enabled also by '-Wconversion'.
1
1 '-Wfloat-conversion'
1 Warn for implicit conversions that reduce the precision of a real
1 value. This includes conversions from real to integer, and from
1 higher precision real to lower precision real values. This option
1 is also enabled by '-Wconversion'.
1
1 '-Wno-scalar-storage-order'
1 Do not warn on suspicious constructs involving reverse scalar
1 storage order.
1
1 '-Wsized-deallocation (C++ and Objective-C++ only)'
1 Warn about a definition of an unsized deallocation function
1 void operator delete (void *) noexcept;
1 void operator delete[] (void *) noexcept;
1 without a definition of the corresponding sized deallocation
1 function
1 void operator delete (void *, std::size_t) noexcept;
1 void operator delete[] (void *, std::size_t) noexcept;
1 or vice versa. Enabled by '-Wextra' along with
1 '-fsized-deallocation'.
1
1 '-Wsizeof-pointer-div'
1 Warn for suspicious divisions of two sizeof expressions that divide
1 the pointer size by the element size, which is the usual way to
1 compute the array size but won't work out correctly with pointers.
1 This warning warns e.g. about 'sizeof (ptr) / sizeof (ptr[0])' if
1 'ptr' is not an array, but a pointer. This warning is enabled by
1 '-Wall'.
1
1 '-Wsizeof-pointer-memaccess'
1 Warn for suspicious length parameters to certain string and memory
1 built-in functions if the argument uses 'sizeof'. This warning
1 triggers for example for 'memset (ptr, 0, sizeof (ptr));' if 'ptr'
1 is not an array, but a pointer, and suggests a possible fix, or
1 about 'memcpy (&foo, ptr, sizeof (&foo));'.
1 '-Wsizeof-pointer-memaccess' also warns about calls to bounded
1 string copy functions like 'strncat' or 'strncpy' that specify as
1 the bound a 'sizeof' expression of the source array. For example,
1 in the following function the call to 'strncat' specifies the size
1 of the source string as the bound. That is almost certainly a
1 mistake and so the call is diagnosed.
1 void make_file (const char *name)
1 {
1 char path[PATH_MAX];
1 strncpy (path, name, sizeof path - 1);
1 strncat (path, ".text", sizeof ".text");
1 ...
1 }
1
1 The '-Wsizeof-pointer-memaccess' option is enabled by '-Wall'.
1
1 '-Wsizeof-array-argument'
1 Warn when the 'sizeof' operator is applied to a parameter that is
1 declared as an array in a function definition. This warning is
1 enabled by default for C and C++ programs.
1
1 '-Wmemset-elt-size'
1 Warn for suspicious calls to the 'memset' built-in function, if the
1 first argument references an array, and the third argument is a
1 number equal to the number of elements, but not equal to the size
1 of the array in memory. This indicates that the user has omitted a
1 multiplication by the element size. This warning is enabled by
1 '-Wall'.
1
1 '-Wmemset-transposed-args'
1 Warn for suspicious calls to the 'memset' built-in function, if the
1 second argument is not zero and the third argument is zero. This
1 warns e.g. about 'memset (buf, sizeof buf, 0)' where most probably
1 'memset (buf, 0, sizeof buf)' was meant instead. The diagnostics
1 is only emitted if the third argument is literal zero. If it is
1 some expression that is folded to zero, a cast of zero to some
1 type, etc., it is far less likely that the user has mistakenly
1 exchanged the arguments and no warning is emitted. This warning is
1 enabled by '-Wall'.
1
1 '-Waddress'
1 Warn about suspicious uses of memory addresses. These include
1 using the address of a function in a conditional expression, such
1 as 'void func(void); if (func)', and comparisons against the memory
1 address of a string literal, such as 'if (x == "abc")'. Such uses
1 typically indicate a programmer error: the address of a function
1 always evaluates to true, so their use in a conditional usually
1 indicate that the programmer forgot the parentheses in a function
1 call; and comparisons against string literals result in unspecified
1 behavior and are not portable in C, so they usually indicate that
1 the programmer intended to use 'strcmp'. This warning is enabled
1 by '-Wall'.
1
1 '-Wlogical-op'
1 Warn about suspicious uses of logical operators in expressions.
1 This includes using logical operators in contexts where a bit-wise
1 operator is likely to be expected. Also warns when the operands of
1 a logical operator are the same:
1 extern int a;
1 if (a < 0 && a < 0) { ... }
1
1 '-Wlogical-not-parentheses'
1 Warn about logical not used on the left hand side operand of a
1 comparison. This option does not warn if the right operand is
1 considered to be a boolean expression. Its purpose is to detect
1 suspicious code like the following:
1 int a;
1 ...
1 if (!a > 1) { ... }
1
1 It is possible to suppress the warning by wrapping the LHS into
1 parentheses:
1 if ((!a) > 1) { ... }
1
1 This warning is enabled by '-Wall'.
1
1 '-Waggregate-return'
1 Warn if any functions that return structures or unions are defined
1 or called. (In languages where you can return an array, this also
1 elicits a warning.)
1
1 '-Wno-aggressive-loop-optimizations'
1 Warn if in a loop with constant number of iterations the compiler
1 detects undefined behavior in some statement during one or more of
1 the iterations.
1
1 '-Wno-attributes'
1 Do not warn if an unexpected '__attribute__' is used, such as
1 unrecognized attributes, function attributes applied to variables,
1 etc. This does not stop errors for incorrect use of supported
1 attributes.
1
1 '-Wno-builtin-declaration-mismatch'
1 Warn if a built-in function is declared with the wrong signature or
1 as non-function. This warning is enabled by default.
1
1 '-Wno-builtin-macro-redefined'
1 Do not warn if certain built-in macros are redefined. This
1 suppresses warnings for redefinition of '__TIMESTAMP__',
1 '__TIME__', '__DATE__', '__FILE__', and '__BASE_FILE__'.
1
1 '-Wstrict-prototypes (C and Objective-C only)'
1 Warn if a function is declared or defined without specifying the
1 argument types. (An old-style function definition is permitted
1 without a warning if preceded by a declaration that specifies the
1 argument types.)
1
1 '-Wold-style-declaration (C and Objective-C only)'
1 Warn for obsolescent usages, according to the C Standard, in a
1 declaration. For example, warn if storage-class specifiers like
1 'static' are not the first things in a declaration. This warning
1 is also enabled by '-Wextra'.
1
1 '-Wold-style-definition (C and Objective-C only)'
1 Warn if an old-style function definition is used. A warning is
1 given even if there is a previous prototype.
1
1 '-Wmissing-parameter-type (C and Objective-C only)'
1 A function parameter is declared without a type specifier in
1 K&R-style functions:
1
1 void foo(bar) { }
1
1 This warning is also enabled by '-Wextra'.
1
1 '-Wmissing-prototypes (C and Objective-C only)'
1 Warn if a global function is defined without a previous prototype
1 declaration. This warning is issued even if the definition itself
1 provides a prototype. Use this option to detect global functions
1 that do not have a matching prototype declaration in a header file.
1 This option is not valid for C++ because all function declarations
1 provide prototypes and a non-matching declaration declares an
1 overload rather than conflict with an earlier declaration. Use
1 '-Wmissing-declarations' to detect missing declarations in C++.
1
1 '-Wmissing-declarations'
1 Warn if a global function is defined without a previous
1 declaration. Do so even if the definition itself provides a
1 prototype. Use this option to detect global functions that are not
1 declared in header files. In C, no warnings are issued for
1 functions with previous non-prototype declarations; use
1 '-Wmissing-prototypes' to detect missing prototypes. In C++, no
1 warnings are issued for function templates, or for inline
1 functions, or for functions in anonymous namespaces.
1
1 '-Wmissing-field-initializers'
1 Warn if a structure's initializer has some fields missing. For
1 example, the following code causes such a warning, because 'x.h' is
1 implicitly zero:
1
1 struct s { int f, g, h; };
1 struct s x = { 3, 4 };
1
1 This option does not warn about designated initializers, so the
1 following modification does not trigger a warning:
1
1 struct s { int f, g, h; };
1 struct s x = { .f = 3, .g = 4 };
1
1 In C this option does not warn about the universal zero initializer
1 '{ 0 }':
1
1 struct s { int f, g, h; };
1 struct s x = { 0 };
1
1 Likewise, in C++ this option does not warn about the empty { }
1 initializer, for example:
1
1 struct s { int f, g, h; };
1 s x = { };
1
1 This warning is included in '-Wextra'. To get other '-Wextra'
1 warnings without this one, use '-Wextra
1 -Wno-missing-field-initializers'.
1
1 '-Wno-multichar'
1 Do not warn if a multicharacter constant (''FOOF'') is used.
1 Usually they indicate a typo in the user's code, as they have
1 implementation-defined values, and should not be used in portable
1 code.
1
1 '-Wnormalized=[none|id|nfc|nfkc]'
1 In ISO C and ISO C++, two identifiers are different if they are
1 different sequences of characters. However, sometimes when
1 characters outside the basic ASCII character set are used, you can
1 have two different character sequences that look the same. To
1 avoid confusion, the ISO 10646 standard sets out some
1 "normalization rules" which when applied ensure that two sequences
1 that look the same are turned into the same sequence. GCC can warn
1 you if you are using identifiers that have not been normalized;
1 this option controls that warning.
1
1 There are four levels of warning supported by GCC. The default is
1 '-Wnormalized=nfc', which warns about any identifier that is not in
1 the ISO 10646 "C" normalized form, "NFC". NFC is the recommended
1 form for most uses. It is equivalent to '-Wnormalized'.
1
1 Unfortunately, there are some characters allowed in identifiers by
1 ISO C and ISO C++ that, when turned into NFC, are not allowed in
1 identifiers. That is, there's no way to use these symbols in
1 portable ISO C or C++ and have all your identifiers in NFC.
1 '-Wnormalized=id' suppresses the warning for these characters. It
1 is hoped that future versions of the standards involved will
1 correct this, which is why this option is not the default.
1
1 You can switch the warning off for all characters by writing
1 '-Wnormalized=none' or '-Wno-normalized'. You should only do this
1 if you are using some other normalization scheme (like "D"),
1 because otherwise you can easily create bugs that are literally
1 impossible to see.
1
1 Some characters in ISO 10646 have distinct meanings but look
1 identical in some fonts or display methodologies, especially once
1 formatting has been applied. For instance '\u207F', "SUPERSCRIPT
1 LATIN SMALL LETTER N", displays just like a regular 'n' that has
1 been placed in a superscript. ISO 10646 defines the "NFKC"
1 normalization scheme to convert all these into a standard form as
1 well, and GCC warns if your code is not in NFKC if you use
1 '-Wnormalized=nfkc'. This warning is comparable to warning about
1 every identifier that contains the letter O because it might be
1 confused with the digit 0, and so is not the default, but may be
1 useful as a local coding convention if the programming environment
1 cannot be fixed to display these characters distinctly.
1
1 '-Wno-deprecated'
11 Do not warn about usage of deprecated features. ⇒Deprecated
Features.
1
1 '-Wno-deprecated-declarations'
1 Do not warn about uses of functions (⇒Function Attributes),
DONTPRINTYET 1 variables (⇒Variable Attributes), and types (*noteType
1 Attributes::) marked as deprecated by using the 'deprecated'
1 attribute.
1
1 '-Wno-overflow'
1 Do not warn about compile-time overflow in constant expressions.
1
1 '-Wno-odr'
1 Warn about One Definition Rule violations during link-time
1 optimization. Requires '-flto-odr-type-merging' to be enabled.
1 Enabled by default.
1
1 '-Wopenmp-simd'
1 Warn if the vectorizer cost model overrides the OpenMP simd
1 directive set by user. The '-fsimd-cost-model=unlimited' option
1 can be used to relax the cost model.
1
1 '-Woverride-init (C and Objective-C only)'
1 Warn if an initialized field without side effects is overridden
11 when using designated initializers (⇒Designated Initializers
Designated Inits.).
1
1 This warning is included in '-Wextra'. To get other '-Wextra'
1 warnings without this one, use '-Wextra -Wno-override-init'.
1
1 '-Woverride-init-side-effects (C and Objective-C only)'
1 Warn if an initialized field with side effects is overridden when
11 using designated initializers (⇒Designated Initializers
Designated Inits.). This warning is enabled by default.
1
1 '-Wpacked'
1 Warn if a structure is given the packed attribute, but the packed
1 attribute has no effect on the layout or size of the structure.
1 Such structures may be mis-aligned for little benefit. For
1 instance, in this code, the variable 'f.x' in 'struct bar' is
1 misaligned even though 'struct bar' does not itself have the packed
1 attribute:
1
1 struct foo {
1 int x;
1 char a, b, c, d;
1 } __attribute__((packed));
1 struct bar {
1 char z;
1 struct foo f;
1 };
1
1 '-Wpacked-bitfield-compat'
1 The 4.1, 4.2 and 4.3 series of GCC ignore the 'packed' attribute on
1 bit-fields of type 'char'. This has been fixed in GCC 4.4 but the
1 change can lead to differences in the structure layout. GCC
1 informs you when the offset of such a field has changed in GCC 4.4.
1 For example there is no longer a 4-bit padding between field 'a'
1 and 'b' in this structure:
1
1 struct foo
1 {
1 char a:4;
1 char b:8;
1 } __attribute__ ((packed));
1
1 This warning is enabled by default. Use
1 '-Wno-packed-bitfield-compat' to disable this warning.
1
1 '-Wpacked-not-aligned (C, C++, Objective-C and Objective-C++ only)'
1 Warn if a structure field with explicitly specified alignment in a
1 packed struct or union is misaligned. For example, a warning will
1 be issued on 'struct S', like, 'warning: alignment 1 of 'struct S'
1 is less than 8', in this code:
1
1 struct __attribute__ ((aligned (8))) S8 { char a[8]; };
1 struct __attribute__ ((packed)) S {
1 struct S8 s8;
1 };
1
1 This warning is enabled by '-Wall'.
1
1 '-Wpadded'
1 Warn if padding is included in a structure, either to align an
1 element of the structure or to align the whole structure.
1 Sometimes when this happens it is possible to rearrange the fields
1 of the structure to reduce the padding and so make the structure
1 smaller.
1
1 '-Wredundant-decls'
1 Warn if anything is declared more than once in the same scope, even
1 in cases where multiple declaration is valid and changes nothing.
1
1 '-Wno-restrict'
1 Warn when an object referenced by a 'restrict'-qualified parameter
1 (or, in C++, a '__restrict'-qualified parameter) is aliased by
1 another argument, or when copies between such objects overlap. For
1 example, the call to the 'strcpy' function below attempts to
1 truncate the string by replacing its initial characters with the
1 last four. However, because the call writes the terminating NUL
1 into 'a[4]', the copies overlap and the call is diagnosed.
1
1 void foo (void)
1 {
1 char a[] = "abcd1234";
1 strcpy (a, a + 4);
1 ...
1 }
1 The '-Wrestrict' option detects some instances of simple overlap
1 even without optimization but works best at '-O2' and above. It is
1 included in '-Wall'.
1
1 '-Wnested-externs (C and Objective-C only)'
1 Warn if an 'extern' declaration is encountered within a function.
1
1 '-Wno-inherited-variadic-ctor'
1 Suppress warnings about use of C++11 inheriting constructors when
1 the base class inherited from has a C variadic constructor; the
1 warning is on by default because the ellipsis is not inherited.
1
1 '-Winline'
1 Warn if a function that is declared as inline cannot be inlined.
1 Even with this option, the compiler does not warn about failures to
1 inline functions declared in system headers.
1
1 The compiler uses a variety of heuristics to determine whether or
1 not to inline a function. For example, the compiler takes into
1 account the size of the function being inlined and the amount of
1 inlining that has already been done in the current function.
1 Therefore, seemingly insignificant changes in the source program
1 can cause the warnings produced by '-Winline' to appear or
1 disappear.
1
1 '-Wno-invalid-offsetof (C++ and Objective-C++ only)'
1 Suppress warnings from applying the 'offsetof' macro to a non-POD
1 type. According to the 2014 ISO C++ standard, applying 'offsetof'
1 to a non-standard-layout type is undefined. In existing C++
1 implementations, however, 'offsetof' typically gives meaningful
1 results. This flag is for users who are aware that they are
1 writing nonportable code and who have deliberately chosen to ignore
1 the warning about it.
1
1 The restrictions on 'offsetof' may be relaxed in a future version
1 of the C++ standard.
1
1 '-Wint-in-bool-context'
1 Warn for suspicious use of integer values where boolean values are
1 expected, such as conditional expressions (?:) using non-boolean
1 integer constants in boolean context, like 'if (a <= b ? 2 : 3)'.
1 Or left shifting of signed integers in boolean context, like 'for
1 (a = 0; 1 << a; a++);'. Likewise for all kinds of multiplications
1 regardless of the data type. This warning is enabled by '-Wall'.
1
1 '-Wno-int-to-pointer-cast'
1 Suppress warnings from casts to pointer type of an integer of a
1 different size. In C++, casting to a pointer type of smaller size
1 is an error. 'Wint-to-pointer-cast' is enabled by default.
1
1 '-Wno-pointer-to-int-cast (C and Objective-C only)'
1 Suppress warnings from casts from a pointer to an integer type of a
1 different size.
1
1 '-Winvalid-pch'
1 Warn if a precompiled header (⇒Precompiled Headers) is found
1 in the search path but cannot be used.
1
1 '-Wlong-long'
1 Warn if 'long long' type is used. This is enabled by either
1 '-Wpedantic' or '-Wtraditional' in ISO C90 and C++98 modes. To
1 inhibit the warning messages, use '-Wno-long-long'.
1
1 '-Wvariadic-macros'
1 Warn if variadic macros are used in ISO C90 mode, or if the GNU
1 alternate syntax is used in ISO C99 mode. This is enabled by
1 either '-Wpedantic' or '-Wtraditional'. To inhibit the warning
1 messages, use '-Wno-variadic-macros'.
1
1 '-Wvarargs'
1 Warn upon questionable usage of the macros used to handle variable
1 arguments like 'va_start'. This is default. To inhibit the
1 warning messages, use '-Wno-varargs'.
1
1 '-Wvector-operation-performance'
1 Warn if vector operation is not implemented via SIMD capabilities
1 of the architecture. Mainly useful for the performance tuning.
1 Vector operation can be implemented 'piecewise', which means that
1 the scalar operation is performed on every vector element; 'in
1 parallel', which means that the vector operation is implemented
1 using scalars of wider type, which normally is more performance
1 efficient; and 'as a single scalar', which means that vector fits
1 into a scalar type.
1
1 '-Wno-virtual-move-assign'
1 Suppress warnings about inheriting from a virtual base with a
1 non-trivial C++11 move assignment operator. This is dangerous
1 because if the virtual base is reachable along more than one path,
1 it is moved multiple times, which can mean both objects end up in
1 the moved-from state. If the move assignment operator is written
1 to avoid moving from a moved-from object, this warning can be
1 disabled.
1
1 '-Wvla'
1 Warn if a variable-length array is used in the code. '-Wno-vla'
1 prevents the '-Wpedantic' warning of the variable-length array.
1
1 '-Wvla-larger-than=N'
1 If this option is used, the compiler will warn on uses of
1 variable-length arrays where the size is either unbounded, or
1 bounded by an argument that can be larger than N bytes. This is
1 similar to how '-Walloca-larger-than=N' works, but with
1 variable-length arrays.
1
1 Note that GCC may optimize small variable-length arrays of a known
1 value into plain arrays, so this warning may not get triggered for
1 such arrays.
1
1 This warning is not enabled by '-Wall', and is only active when
1 '-ftree-vrp' is active (default for '-O2' and above).
1
1 See also '-Walloca-larger-than=N'.
1
1 '-Wvolatile-register-var'
1 Warn if a register variable is declared volatile. The volatile
1 modifier does not inhibit all optimizations that may eliminate
1 reads and/or writes to register variables. This warning is enabled
1 by '-Wall'.
1
1 '-Wdisabled-optimization'
1 Warn if a requested optimization pass is disabled. This warning
1 does not generally indicate that there is anything wrong with your
1 code; it merely indicates that GCC's optimizers are unable to
1 handle the code effectively. Often, the problem is that your code
1 is too big or too complex; GCC refuses to optimize programs when
1 the optimization itself is likely to take inordinate amounts of
1 time.
1
1 '-Wpointer-sign (C and Objective-C only)'
1 Warn for pointer argument passing or assignment with different
1 signedness. This option is only supported for C and Objective-C.
1 It is implied by '-Wall' and by '-Wpedantic', which can be disabled
1 with '-Wno-pointer-sign'.
1
1 '-Wstack-protector'
1 This option is only active when '-fstack-protector' is active. It
1 warns about functions that are not protected against stack
1 smashing.
1
1 '-Woverlength-strings'
1 Warn about string constants that are longer than the "minimum
1 maximum" length specified in the C standard. Modern compilers
1 generally allow string constants that are much longer than the
1 standard's minimum limit, but very portable programs should avoid
1 using longer strings.
1
1 The limit applies _after_ string constant concatenation, and does
1 not count the trailing NUL. In C90, the limit was 509 characters;
1 in C99, it was raised to 4095. C++98 does not specify a normative
1 minimum maximum, so we do not diagnose overlength strings in C++.
1
1 This option is implied by '-Wpedantic', and can be disabled with
1 '-Wno-overlength-strings'.
1
1 '-Wunsuffixed-float-constants (C and Objective-C only)'
1
1 Issue a warning for any floating constant that does not have a
1 suffix. When used together with '-Wsystem-headers' it warns about
1 such constants in system header files. This can be useful when
1 preparing code to use with the 'FLOAT_CONST_DECIMAL64' pragma from
1 the decimal floating-point extension to C99.
1
1 '-Wno-designated-init (C and Objective-C only)'
1 Suppress warnings when a positional initializer is used to
1 initialize a structure that has been marked with the
1 'designated_init' attribute.
1
1 '-Whsa'
1 Issue a warning when HSAIL cannot be emitted for the compiled
1 function or OpenMP construct.
1