neulab/tldr huggingface dataset:
Where the standard specified with -std represents a GNU extended dialect of C, such as gnu90 or gnu99, there is a corresponding base standard, the version of ISO C on which the GNU extended dialect is based.  Warnings from -Wpedantic are given where they are required by the base standard.  (It does not make sense for such warnings to be given only for features not in the specified GNU C dialect, since by definition the GNU dialects of C include all features the compiler supports with the given option, and there would be nothing to warn about.)
-pedantic-errors Give an error whenever the base standard (see -Wpedantic) requires a diagnostic, in some cases where there is undefined behavior at compile-time and in some other cases that do not prevent compilation of programs that are valid according to the standard. This is not equivalent to -Werror=pedantic, since there are errors enabled by this option and not enabled by the latter and vice versa.
-Wall This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.  This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.
-Wall turns on the following warning flags:
-Waddress -Warray-bounds=1 (only with -O2) -Warray-parameter=2 (C and Objective-C only) -Wbool-compare -Wbool-operation -Wc++11-compat -Wc++14-compat -Wcatch-value (C++ and Objective-C++ only) -Wchar-subscripts -Wcomment -Wduplicate-decl-specifier (C and Objective-C only) -Wenum-compare (in C/ObjC; this is on by default in C++) -Wformat -Wformat-overflow -Wformat-truncation -Wint-in-bool-context -Wimplicit (C and Objective-C only) -Wimplicit-int (C and Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) -Winit-self (only for C++) -Wlogical-not-parentheses -Wmain (only for C/ObjC and unless -ffreestanding) -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation (only for C/C++) -Wmissing-attributes -Wmissing-braces (only for C/ObjC) -Wmultistatement-macros -Wnarrowing (only for C++) -Wnonnull -Wnonnull-compare -Wopenmp-simd -Wparentheses -Wpessimizing-move (only for C++) -Wpointer-sign -Wrange-loop-construct (only for C++) -Wreorder -Wrestrict -Wreturn-type -Wsequence-point -Wsign-compare (only in C++) -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtautological-compare -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvla-parameter (C and Objective-C only) -Wvolatile-register-var -Wzero-length-bounds
Note that some warning flags are not implied by -Wall.  Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by -Wextra but many of them must be enabled individually.
-Wextra This enables some extra warning flags that are not enabled by -Wall. (This option used to be called -W.  The older name is still supported, but the newer name is more descriptive.)
-Wclobbered -Wcast-function-type -Wdeprecated-copy (C++ only) -Wempty-body -Wenum-conversion (C only) -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wmissing-field-initializers -Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init -Wsign-compare (C only) -Wstring-compare -Wredundant-move (only for C++) -Wtype-limits -Wuninitialized -Wshift-negative-value (in C++03 and in C99 and newer) -Wunused-parameter (only with -Wunused or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall)
The option -Wextra also prints warning messages for the following cases:
*   A pointer is compared against integer zero with "<", "<=", ">", or ">=".
*   (C++ only) An enumerator and a non-enumerator both appear in a conditional expression.
*   (C++ only) Ambiguous virtual bases.
*   (C++ only) Subscripting an array that has been declared "register".
*   (C++ only) Taking the address of a variable that has been declared "register".
*   (C++ only) A base class is not initialized in the copy constructor of a derived class.
-Wabi (C, Objective-C, C++ and Objective-C++ only) Warn about code affected by ABI changes.  This includes code that may not be compatible with the vendor-neutral C++ ABI as well as the psABI for the particular target.
Since G++ now defaults to updating the ABI with each major release, normally -Wabi warns only about C++ ABI compatibility problems if there is a check added later in a release series for an ABI issue discovered since the initial release.  -Wabi warns about more things if an older ABI version is selected (with -fabi-version=n).
-Wabi can also be used with an explicit version number to warn about C++ ABI compatibility with a particular -fabi-version level, e.g. -Wabi=2 to warn about changes relative to -fabi-version=2.
If an explicit version number is provided and -fabi-compat-version is not specified, the version number from this option is used for compatibility aliases.  If no explicit version number is provided with this option, but -fabi-compat-version is specified, that version number is used for C++ ABI warnings.
Although an effort has been made to warn about all such cases, there are probably some cases that are not warned about, even though G++ is generating incompatible code.  There may also be cases where warnings are emitted even though the code that is generated is compatible.
You should rewrite your code to avoid these warnings if you are concerned about the fact that code generated by G++ may not be binary compatible with code generated by other compilers.
Known incompatibilities in -fabi-version=2 (which was the default from GCC 3.4 to 4.9) include:
*   A template with a non-type template parameter of reference type was mangled incorrectly:
extern int N; template <int &> struct S {}; void n (S<N>) {2}
This was fixed in -fabi-version=3.
*   SIMD vector types declared using "__attribute ((vector_size))" were mangled in a non-standard way that does not allow for overloading of functions taking vectors of different sizes.
The mangling was changed in -fabi-version=4.
*   "__attribute ((const))" and "noreturn" were mangled as type qualifiers, and "decltype" of a plain declaration was folded away.
These mangling issues were fixed in -fabi-version=5.
*   Scoped enumerators passed as arguments to a variadic function are promoted like unscoped enumerators, causing "va_arg" to complain. On most targets this does not actually affect the parameter passing ABI, as there is no way to pass an argument smaller than "int".
Also, the ABI changed the mangling of template argument packs, "const_cast", "static_cast", prefix increment/decrement, and a class scope function used as a template argument.
These issues were corrected in -fabi-version=6.
*   Lambdas in default argument scope were mangled incorrectly, and the ABI changed the mangling of "nullptr_t".
These issues were corrected in -fabi-version=7.
*   When mangling a function type with function-cv-qualifiers, the un-qualified function type was incorrectly treated as a substitution candidate.
This was fixed in -fabi-version=8, the default for GCC 5.1.
*   "decltype(nullptr)" incorrectly had an alignment of 1, leading to unaligned accesses.  Note that this did not affect the ABI of a function with a "nullptr_t" parameter, as parameters have a minimum alignment.
This was fixed in -fabi-version=9, the default for GCC 5.2.
*   Target-specific attributes that affect the identity of a type, such as ia32 calling conventions on a function type (stdcall, regparm, etc.), did not affect the mangled name, leading to name collisions when function pointers were used as template arguments.
This was fixed in -fabi-version=10, the default for GCC 6.1.
This option also enables warnings about psABI-related changes.  The known psABI changes at this point include:
*   For SysV/x86-64, unions with "long double" members are passed in memory as specified in psABI.  Prior to GCC 4.4, this was not the case.  For example:
union U { long double ld; int i; };
"union U" is now always passed in memory.
-Wchar-subscripts Warn if an array subscript has type "char".  This is a common cause of error, as programmers often forget that this type is signed on some machines.  This warning is enabled by -Wall.
-Wno-coverage-mismatch Warn if feedback profiles do not match when using the -fprofile-use option.  If a source file is changed between compiling with -fprofile-generate and with -fprofile-use, the files with the profile feedback can fail to match the source file and GCC cannot use the profile feedback information.  By default, this warning is enabled and is treated as an error.  -Wno-coverage-mismatch can be used to disable the warning or -Wno-error=coverage-mismatch can be used to disable the error.  Disabling the error for this warning can result in poorly optimized code and is useful only in the case of very minor changes such as bug fixes to an existing code-base.  Completely disabling the warning is not recommended.
-Wno-cpp (C, Objective-C, C++, Objective-C++ and Fortran only) Suppress warning messages emitted by "#warning" directives.
-Wdouble-promotion (C, C++, Objective-C and Objective-C++ only) Give a warning when a value of type "float" is implicitly promoted to "double".  CPUs with a 32-bit "single-precision" floating-point unit implement "float" in hardware, but emulate "double" in software.  On such a machine, doing computations using "double" values is much more expensive because of the overhead required for software emulation.
It is easy to accidentally do computations with "double" because floating-point literals are implicitly of type "double".  For example, in:
float area(float radius) { return 3.14159 * radius * radius; }
the compiler performs the entire computation with "double" because the floating-point literal is a "double".
-Wduplicate-decl-specifier (C and Objective-C only) Warn if a declaration has duplicate "const", "volatile", "restrict" or "_Atomic" specifier.  This warning is enabled by -Wall.
-Wformat -Wformat=n Check calls to "printf" and "scanf", etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense.  This includes standard functions, and others specified by format attributes, in the "printf", "scanf", "strftime" and "strfmon" (an X/Open extension, not in the C standard) families (or other target-specific families).  Which functions are checked without format attributes having been specified depends on the standard version selected, and such checks of functions without the attribute specified are disabled by -ffreestanding or -fno-builtin.
The formats are checked against the format features supported by GNU libc version 2.2.  These include all ISO C90 and C99 features, as well as features from the Single Unix Specification and some BSD and GNU extensions.  Other library implementations may not support all these features; GCC does not support warning about features that go beyond a particular library's limitations.  However, if -Wpedantic is used with -Wformat, warnings are given about format features not in the selected standard version (but not for "strfmon" formats, since those are not in any version of the C standard).
-Wformat=1 -Wformat Option -Wformat is equivalent to -Wformat=1, and -Wno-format is equivalent to -Wformat=0.  Since -Wformat also checks for null format arguments for several functions, -Wformat also implies -Wnonnull.  Some aspects of this level of format checking can be disabled by the options: -Wno-format-contains-nul, -Wno-format-extra-args, and -Wno-format-zero-length.  -Wformat is enabled by -Wall.
-Wformat=2 Enable -Wformat plus additional format checks.  Currently equivalent to -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k.
-Wno-format-contains-nul If -Wformat is specified, do not warn about format strings that contain NUL bytes.
-Wno-format-extra-args If -Wformat is specified, do not warn about excess arguments to a "printf" or "scanf" format function.  The C standard specifies that such arguments are ignored.
Where the unused arguments lie between used arguments that are specified with $ operand number specifications, normally warnings are still given, since the implementation could not know what type to pass to "va_arg" to skip the unused arguments.  However, in the case of "scanf" formats, this option suppresses the warning if the unused arguments are all pointers, since the Single Unix Specification says that such unused arguments are allowed.
-Wformat-overflow -Wformat-overflow=level Warn about calls to formatted input/output functions such as "sprintf" and "vsprintf" that might overflow the destination buffer. When the exact number of bytes written by a format directive cannot be determined at compile-time it is estimated based on heuristics that depend on the level argument and on optimization.  While enabling optimization will in most cases improve the accuracy of the warning, it may also result in false positives.
-Wformat-overflow -Wformat-overflow=1 Level 1 of -Wformat-overflow enabled by -Wformat employs a conservative approach that warns only about calls that most likely overflow the buffer.  At this level, numeric arguments to format directives with unknown values are assumed to have the value of one, and strings of unknown length to be empty.  Numeric arguments that are known to be bounded to a subrange of their type, or string arguments whose output is bounded either by their directive's precision or by a finite set of string literals, are assumed to take on the value within the range that results in the most bytes on output.  For example, the call to "sprintf" below is diagnosed because even with both a and b equal to zero, the terminating NUL character ('\0') appended by the function to the destination buffer will be written past its end.  Increasing the size of the buffer by a single byte is sufficient to avoid the warning, though it may not be sufficient to avoid the overflow.
void f (int a, int b) { char buf [13]; sprintf (buf, "a = %i, b = %i\n", a, b); }
-Wformat-overflow=2 Level 2 warns also about calls that might overflow the destination buffer given an argument of sufficient length or magnitude.  At level 2, unknown numeric arguments are assumed to have the minimum representable value for signed types with a precision greater than 1, and the maximum representable value otherwise.  Unknown string arguments whose length cannot be assumed to be bounded either by the directive's precision, or by a finite set of string literals they may evaluate to, or the character array they may point to, are assumed to be 1 character long.
At level 2, the call in the example above is again diagnosed, but this time because with a equal to a 32-bit "INT_MIN" the first %i directive will write some of its digits beyond the end of the destination buffer.  To make the call safe regardless of the values of the two variables, the size of the destination buffer must be increased to at least 34 bytes.  GCC includes the minimum size of the buffer in an informational note following the warning.
An alternative to increasing the size of the destination buffer is to constrain the range of formatted values.  The maximum length of string arguments can be bounded by specifying the precision in the format directive.  When numeric arguments of format directives can be assumed to be bounded by less than the precision of their type, choosing an appropriate length modifier to the format specifier will reduce the required buffer size. For example, if a and b in the example above can be assumed to be within the precision of the "short int" type then using either the %hi format directive or casting the argument to "short" reduces the maximum required size of the buffer to 24 bytes.
void f (int a, int b) { char buf [23]; sprintf (buf, "a = %hi, b = %i\n", a, (short)b); }
-Wno-format-zero-length If -Wformat is specified, do not warn about zero-length formats.  The C standard specifies that zero-length formats are allowed.
-Wformat-nonliteral If -Wformat is specified, also warn if the format string is not a string literal and so cannot be checked, unless the format function takes its format arguments as a "va_list".
-Wformat-security If -Wformat is specified, also warn about uses of format functions that represent possible security problems.  At present, this warns about calls to "printf" and "scanf" functions where the format string is not a string literal and there are no format arguments, as in "printf (foo);".  This may be a security hole if the format string came from untrusted input and contains %n.  (This is currently a subset of what -Wformat-nonliteral warns about, but in future warnings may be added to -Wformat-security that are not included in -Wformat-nonliteral.)
-Wformat-signedness If -Wformat is specified, also warn if the format string requires an unsigned argument and the argument is signed and vice versa.
-Wformat-truncation -Wformat-truncation=level Warn about calls to formatted input/output functions such as "snprintf" and "vsnprintf" that might result in output truncation. When the exact number of bytes written by a format directive cannot be determined at compile-time it is estimated based on heuristics that depend on the level argument and on optimization.  While enabling optimization will in most cases improve the accuracy of the warning, it may also result in false positives.  Except as noted otherwise, the option uses the same logic -Wformat-overflow.
-Wformat-truncation -Wformat-truncation=1 Level 1 of -Wformat-truncation enabled by -Wformat employs a conservative approach that warns only about calls to bounded functions whose return value is unused and that will most likely result in output truncation.
-Wformat-truncation=2 Level 2 warns also about calls to bounded functions whose return value is used and that might result in truncation given an argument of sufficient length or magnitude.
-Wformat-y2k If -Wformat is specified, also warn about "strftime" formats that may yield only a two-digit year.
-Wnonnull Warn about passing a null pointer for arguments marked as requiring a non-null value by the "nonnull" function attribute.
-Wnonnull is included in -Wall and -Wformat.  It can be disabled with the -Wno-nonnull option.
-Wnonnull-compare Warn when comparing an argument marked with the "nonnull" function attribute against null inside the function.
-Wnonnull-compare is included in -Wall.  It can be disabled with the -Wno-nonnull-compare option.
-Wnull-dereference Warn if the compiler detects paths that trigger erroneous or undefined behavior due to dereferencing a null pointer.  This option is only active when -fdelete-null-pointer-checks is active, which is enabled by optimizations in most targets.  The precision of the warnings depends on the optimization options used.
-Winit-self (C, C++, Objective-C and Objective-C++ only) Warn about uninitialized variables that are initialized with themselves.  Note this option can only be used with the -Wuninitialized option.
For example, GCC warns about "i" being uninitialized in the following snippet only when -Winit-self has been specified:
int f() { int i = i; return i; }
This warning is enabled by -Wall in C++.
-Wno-implicit-int (C and Objective-C only) This option controls warnings when a declaration does not specify a type.  This warning is enabled by default in C99 and later dialects of C, and also by -Wall.
-Wno-implicit-function-declaration (C and Objective-C only) This option controls warnings when a function is used before being declared.  This warning is enabled by default in C99 and later dialects of C, and also by -Wall.  The warning is made into an error by -pedantic-errors.
-Wimplicit (C and Objective-C only) Same as -Wimplicit-int and -Wimplicit-function-declaration.  This warning is enabled by -Wall.
-Wimplicit-fallthrough -Wimplicit-fallthrough is the same as -Wimplicit-fallthrough=3 and -Wno-implicit-fallthrough is the same as -Wimplicit-fallthrough=0.
-Wimplicit-fallthrough=n Warn when a switch case falls through.  For example:
switch (cond) { case 1: a = 1; break; case 2: a = 2; case 3: a = 3; break; }
This warning does not warn when the last statement of a case cannot fall through, e.g. when there is a return statement or a call to function declared with the noreturn attribute. -Wimplicit-fallthrough= also takes into account control flow statements, such as ifs, and only warns when appropriate.  E.g.
switch (cond) { case 1: if (i > 3) { bar (5); break; } else if (i < 1) { bar (0); } else return; default: ... }
Since there are occasions where a switch case fall through is desirable, GCC provides an attribute, "__attribute__ ((fallthrough))", that is to be used along with a null statement to suppress this warning that would normally occur:
switch (cond) { case 1: bar (0); __attribute__ ((fallthrough)); default: ... }
C++17 provides a standard way to suppress the -Wimplicit-fallthrough warning using "[[fallthrough]];" instead of the GNU attribute.  In C++11 or C++14 users can use "[[gnu::fallthrough]];", which is a GNU extension.  Instead of these attributes, it is also possible to add a fallthrough comment to silence the warning.  The whole body of the C or C++ style comment should match the given regular expressions listed below.  The option argument n specifies what kind of comments are accepted:
*<-Wimplicit-fallthrough=0 disables the warning altogether.> *<-Wimplicit-fallthrough=1 matches ".*" regular> expression, any comment is used as fallthrough comment.
*<-Wimplicit-fallthrough=2 case insensitively matches> ".*falls?[ \t-]*thr(ough|u).*" regular expression.
*<-Wimplicit-fallthrough=3 case sensitively matches one of the> following regular expressions:
*<"-fallthrough"> *<"@fallthrough@"> *<"lint -fallthrough[ \t]*"> *<"[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?"> *<"[ \t.!]*(Else,? |Intentional(ly)? )?Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?"> *<"[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?"> *<-Wimplicit-fallthrough=4 case sensitively matches one of the> following regular expressions:
*<"-fallthrough"> *<"@fallthrough@"> *<"lint -fallthrough[ \t]*"> *<"[ \t]*FALLTHR(OUGH|U)[ \t]*"> *<-Wimplicit-fallthrough=5 doesn't recognize any comments as> fallthrough comments, only attributes disable the warning.
The comment needs to be followed after optional whitespace and other comments by "case" or "default" keywords or by a user label that precedes some "case" or "default" label.
switch (cond) { case 1: bar (0); /* FALLTHRU */ default: ... }
The -Wimplicit-fallthrough=3 warning is enabled by -Wextra.
-Wno-if-not-aligned (C, C++, Objective-C and Objective-C++ only) Control if warnings triggered by the "warn_if_not_aligned" attribute should be issued.  These warnings are enabled by default.
-Wignored-qualifiers (C and C++ only) Warn if the return type of a function has a type qualifier such as "const".  For ISO C such a type qualifier has no effect, since the value returned by a function is not an lvalue.  For C++, the warning is only emitted for scalar types or "void".  ISO C prohibits qualified "void" return types on function definitions, so such return types always receive a warning even without this option.
This warning is also enabled by -Wextra.
-Wno-ignored-attributes (C and C++ only) This option controls warnings when an attribute is ignored.  This is different from the -Wattributes option in that it warns whenever the compiler decides to drop an attribute, not that the attribute is either unknown, used in a wrong place, etc.  This warning is enabled by default.
-Wmain Warn if the type of "main" is suspicious.  "main" should be a function with external linkage, returning int, taking either zero arguments, two, or three arguments of appropriate types.  This warning is enabled by default in C++ and is enabled by either -Wall or -Wpedantic.
-Wmisleading-indentation (C and C++ only) Warn when the indentation of the code does not reflect the block structure.  Specifically, a warning is issued for "if", "else", "while", and "for" clauses with a guarded statement that does not use braces, followed by an unguarded statement with the same indentation.
In the following example, the call to "bar" is misleadingly indented as if it were guarded by the "if" conditional.
if (some_condition ()) foo (); bar ();  /* Gotcha: this is not guarded by the "if".  */
In the case of mixed tabs and spaces, the warning uses the -ftabstop= option to determine if the statements line up (defaulting to 8).
The warning is not issued for code involving multiline preprocessor logic such as the following example.
if (flagA) foo (0); #if SOME_CONDITION_THAT_DOES_NOT_HOLD if (flagB) #endif foo (1);
The warning is not issued after a "#line" directive, since this typically indicates autogenerated code, and no assumptions can be made about the layout of the file that the directive references.
This warning is enabled by -Wall in C and C++.
-Wmissing-attributes Warn when a declaration of a function is missing one or more attributes that a related function is declared with and whose absence may adversely affect the correctness or efficiency of generated code. For example, the warning is issued for declarations of aliases that use attributes to specify less restrictive requirements than those of their targets.  This typically represents a potential optimization opportunity.  By contrast, the -Wattribute-alias=2 option controls warnings issued when the alias is more restrictive than the target, which could lead to incorrect code generation.  Attributes considered include "alloc_align", "alloc_size", "cold", "const", "hot", "leaf", "malloc", "nonnull", "noreturn", "nothrow", "pure", "returns_nonnull", and "returns_twice".
In C++, the warning is issued when an explicit specialization of a primary template declared with attribute "alloc_align", "alloc_size", "assume_aligned", "format", "format_arg", "malloc", or "nonnull" is declared without it.  Attributes "deprecated", "error", and "warning" suppress the warning..
You can use the "copy" attribute to apply the same set of attributes to a declaration as that on another declaration without explicitly enumerating the attributes. This attribute can be applied to declarations of functions, variables, or types.
-Wmissing-attributes is enabled by -Wall.
For example, since the declaration of the primary function template below makes use of both attribute "malloc" and "alloc_size" the declaration of the explicit specialization of the template is diagnosed because it is missing one of the attributes.
template <class T> T* __attribute__ ((malloc, alloc_size (1))) allocate (size_t);
template <> void* __attribute__ ((malloc))   // missing alloc_size allocate<void> (size_t);
-Wmissing-braces Warn if an aggregate or union initializer is not fully bracketed.  In the following example, the initializer for "a" is not fully bracketed, but that for "b" is fully bracketed.
int a[2][2] = { 0, 1, 2, 3 }; int b[2][2] = { { 0, 1 }, { 2, 3 } };
-Wmissing-include-dirs (C, C++, Objective-C and Objective-C++ only) Warn if a user-supplied include directory does not exist.
-Wno-missing-profile This option controls warnings if feedback profiles are missing when using the -fprofile-use option.  This option diagnoses those cases where a new function or a new file is added between compiling with -fprofile-generate and with -fprofile-use, without regenerating the profiles.  In these cases, the profile feedback data files do not contain any profile feedback information for the newly added function or file respectively.  Also, in the case when profile count data (.gcda) files are removed, GCC cannot use any profile feedback information.  In all these cases, warnings are issued to inform you that a profile generation step is due.  Ignoring the warning can result in poorly optimized code.  -Wno-missing-profile can be used to disable the warning, but this is not recommended and should be done only when non-existent profile data is justified.
-Wno-mismatched-dealloc Warn for calls to deallocation functions with pointer arguments returned from from allocations functions for which the former isn't a suitable deallocator.  A pair of functions can be associated as matching allocators and deallocators by use of attribute "malloc". Unless disabled by the -fno-builtin option the standard functions "calloc", "malloc", "realloc", and "free", as well as the corresponding forms of C++ "operator new" and "operator delete" are implicitly associated as matching allocators and deallocators.  In the following example "mydealloc" is the deallocator for pointers returned from "myalloc".
void mydealloc (void*);
__attribute__ ((malloc (mydealloc, 1))) void* myalloc (size_t);
void f (void) { void *p = myalloc (32); // ...use p... free (p);   // warning: not a matching deallocator for myalloc mydealloc (p);   // ok }
In C++, the related option -Wmismatched-new-delete diagnoses mismatches involving either "operator new" or "operator delete".
Option -Wmismatched-dealloc is enabled by default.
-Wmultistatement-macros Warn about unsafe multiple statement macros that appear to be guarded by a clause such as "if", "else", "for", "switch", or "while", in which only the first statement is actually guarded after the macro is expanded.
#define DOIT x++; y++ if (c) DOIT;
will increment "y" unconditionally, not just when "c" holds.  The can usually be fixed by wrapping the macro in a do-while loop:
#define DOIT do { x++; y++; } while (0) if (c) DOIT;
-Wparentheses Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about.
Also warn if a comparison like "x<=y<=z" appears; this is equivalent to "(x<=y ? 1 : 0) <= z", which is a different interpretation from that of ordinary mathematical notation.
Also warn for dangerous uses of the GNU extension to "?:" with omitted middle operand. When the condition in the "?": operator is a boolean expression, the omitted value is always 1.  Often programmers expect it to be a value computed inside the conditional expression instead.
For C++ this also warns for some cases of unnecessary parentheses in declarations, which can indicate an attempt at a function call instead of a declaration:
{ // Declares a local variable called mymutex. std::unique_lock<std::mutex> (mymutex); // User meant std::unique_lock<std::mutex> lock (mymutex); }
-Wsequence-point Warn about code that may have undefined semantics because of violations of sequence point rules in the C and C++ standards.
The C and C++ standards define the order in which expressions in a C/C++ program are evaluated in terms of sequence points, which represent a partial ordering between the execution of parts of the program: those executed before the sequence point, and those executed after it.  These occur after the evaluation of a full expression (one which is not part of a larger expression), after the evaluation of the first operand of a "&&", "||", "? :" or "," (comma) operator, before a function is called (but after the evaluation of its arguments and the expression denoting the called function), and in certain other places.  Other than as expressed by the sequence point rules, the order of evaluation of subexpressions of an expression is not specified.  All these rules describe only a partial order rather than a total order, since, for example, if two functions are called within one expression with no sequence point between them, the order in which the functions are called is not specified.  However, the standards committee have ruled that function calls do not overlap.
It is not specified when between sequence points modifications to the values of objects take effect.  Programs whose behavior depends on this have undefined behavior; the C and C++ standards specify that "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.  Furthermore, the prior value shall be read only to determine the value to be stored.".  If a program breaks these rules, the results on any particular implementation are entirely unpredictable.
Examples of code with undefined behavior are "a = a++;", "a[n] = b[n++]" and "a[i++] = i;".  Some more complicated cases are not diagnosed by this option, and it may give an occasional false positive result, but in general it has been found fairly effective at detecting this sort of problem in programs.
The C++17 standard will define the order of evaluation of operands in more cases: in particular it requires that the right-hand side of an assignment be evaluated before the left-hand side, so the above examples are no longer undefined.  But this option will still warn about them, to help people avoid writing code that is undefined in C and earlier revisions of C++.
The standard is worded confusingly, therefore there is some debate over the precise meaning of the sequence point rules in subtle cases. Links to discussions of the problem, including proposed formal definitions, may be found on the GCC readings page, at <http://gcc.gnu.org/readings.html>.
This warning is enabled by -Wall for C and C++.
-Wno-return-local-addr Do not warn about returning a pointer (or in C++, a reference) to a variable that goes out of scope after the function returns.
-Wreturn-type Warn whenever a function is defined with a return type that defaults to "int".  Also warn about any "return" statement with no return value in a function whose return type is not "void" (falling off the end of the function body is considered returning without a value).
For C only, warn about a "return" statement with an expression in a function whose return type is "void", unless the expression type is also "void".  As a GNU extension, the latter case is accepted without a warning unless -Wpedantic is used.  Attempting to use the return value of a non-"void" function other than "main" that flows off the end by reaching the closing curly brace that terminates the function is undefined.
Unlike in C, in C++, flowing off the end of a non-"void" function other than "main" results in undefined behavior even when the value of the function is not used.
This warning is enabled by default in C++ and by -Wall otherwise.
-Wno-shift-count-negative Controls warnings if a shift count is negative.  This warning is enabled by default.
-Wno-shift-count-overflow Controls warnings if a shift count is greater than or equal to the bit width of the type.  This warning is enabled by default.
-Wshift-negative-value Warn if left shifting a negative value.  This warning is enabled by -Wextra in C99 and C++11 modes (and newer).
-Wno-shift-overflow -Wshift-overflow=n These options control warnings about left shift overflows.
-Wshift-overflow=1 This is the warning level of -Wshift-overflow and is enabled by default in C99 and C++11 modes (and newer).  This warning level does not warn about left-shifting 1 into the sign bit.  (However, in C, such an overflow is still rejected in contexts where an integer constant expression is required.)  No warning is emitted in C++20 mode (and newer), as signed left shifts always wrap.
-Wshift-overflow=2 This warning level also warns about left-shifting 1 into the sign bit, unless C++14 mode (or newer) is active.
-Wswitch Warn whenever a "switch" statement has an index of enumerated type and lacks a "case" for one or more of the named codes of that enumeration.  (The presence of a "default" label prevents this warning.)  "case" labels outside the enumeration range also provoke warnings when this option is used (even if there is a "default" label).  This warning is enabled by -Wall.
-Wswitch-default Warn whenever a "switch" statement does not have a "default" case.
-Wswitch-enum Warn whenever a "switch" statement has an index of enumerated type and lacks a "case" for one or more of the named codes of that enumeration.  "case" labels outside the enumeration range also provoke warnings when this option is used.  The only difference between -Wswitch and this option is that this option gives a warning about an omitted enumeration code even if there is a "default" label.
-Wno-switch-bool Do not warn when a "switch" statement has an index of boolean type and the case values are outside the range of a boolean type.  It is possible to suppress this warning by casting the controlling expression to a type other than "bool".  For example:
switch ((int) (a == 4)) { ... }
This warning is enabled by default for C and C++ programs.
-Wno-switch-outside-range This option controls warnings when a "switch" case has a value that is outside of its respective type range.  This warning is enabled by default for C and C++ programs.
-Wno-switch-unreachable Do not warn when a "switch" statement contains statements between the controlling expression and the first case label, which will never be executed.  For example:
switch (cond) { i = 15; ... case 5: ... }
-Wswitch-unreachable does not warn if the statement between the controlling expression and the first case label is just a declaration:
switch (cond) { int i; ... case 5: i = 5; ... }
-Wsync-nand (C and C++ only) Warn when "__sync_fetch_and_nand" and "__sync_nand_and_fetch" built- in functions are used.  These functions changed semantics in GCC 4.4.
-Wunused-but-set-parameter Warn whenever a function parameter is assigned to, but otherwise unused (aside from its declaration).
To suppress this warning use the "unused" attribute.
This warning is also enabled by -Wunused together with -Wextra.
-Wunused-but-set-variable Warn whenever a local variable is assigned to, but otherwise unused (aside from its declaration).  This warning is enabled by -Wall.
This warning is also enabled by -Wunused, which is enabled by -Wall.
-Wunused-function Warn whenever a static function is declared but not defined or a non- inline static function is unused.  This warning is enabled by -Wall.
-Wunused-label Warn whenever a label is declared but not used.  This warning is enabled by -Wall.
-Wunused-local-typedefs (C, Objective-C, C++ and Objective-C++ only) Warn when a typedef locally defined in a function is not used.  This warning is enabled by -Wall.
-Wunused-parameter Warn whenever a function parameter is unused aside from its declaration.
-Wno-unused-result Do not warn if a caller of a function marked with attribute "warn_unused_result" does not use its return value. The default is -Wunused-result.
-Wunused-variable Warn whenever a local or static variable is unused aside from its declaration. This option implies -Wunused-const-variable=1 for C, but not for C++. This warning is enabled by -Wall.
-Wunused-const-variable -Wunused-const-variable=n Warn whenever a constant static variable is unused aside from its declaration.  -Wunused-const-variable=1 is enabled by -Wunused-variable for C, but not for C++. In C this declares variable storage, but in C++ this is not an error since const variables take the place of "#define"s.
-Wunused-const-variable=1 This is the warning level that is enabled by -Wunused-variable for C.  It warns only about unused static const variables defined in the main compilation unit, but not about static const variables declared in any header included.
-Wunused-const-variable=2 This warning level also warns for unused constant static variables in headers (excluding system headers).  This is the warning level of -Wunused-const-variable and must be explicitly requested since in C++ this isn't an error and in C it might be harder to clean up all headers included.
-Wunused-value Warn whenever a statement computes a result that is explicitly not used. To suppress this warning cast the unused expression to "void". This includes an expression-statement or the left-hand side of a comma expression that contains no side effects. For example, an expression such as "x[i,j]" causes a warning, while "x[(void)i,j]" does not.
-Wunused All the above -Wunused options combined.
In order to get a warning about an unused function parameter, you must either specify -Wextra -Wunused (note that -Wall implies -Wunused), or separately specify -Wunused-parameter.
-Wuninitialized Warn if an object with automatic or allocated storage duration is used without having been initialized.  In C++, also warn if a non- static reference or non-static "const" member appears in a class without constructors.
In addition, passing a pointer (or in C++, a reference) to an uninitialized object to a "const"-qualified argument of a built-in function known to read the object is also diagnosed by this warning. (-Wmaybe-uninitialized is issued for ordinary functions.)
If you want to warn about code that uses the uninitialized value of the variable in its own initializer, use the -Winit-self option.
These warnings occur for individual uninitialized elements of structure, union or array variables as well as for variables that are uninitialized as a whole.  They do not occur for variables or elements declared "volatile".  Because these warnings depend on optimization, the exact variables or elements for which there are warnings depend on the precise optimization options and version of GCC used.
Note that there may be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data flow analysis before the warnings are printed.
-Wno-invalid-memory-model This option controls warnings for invocations of __atomic Builtins, __sync Builtins, and the C11 atomic generic functions with a memory consistency argument that is either invalid for the operation or outside the range of values of the "memory_order" enumeration.  For example, since the "__atomic_store" and "__atomic_store_n" built-ins are only defined for the relaxed, release, and sequentially consistent memory orders the following code is diagnosed:
void store (int *i) { __atomic_store_n (i, 0, memory_order_consume); }
-Winvalid-memory-model is enabled by default.
-Wmaybe-uninitialized For an object with automatic or allocated storage duration, if there exists a path from the function entry to a use of the object that is initialized, but there exist some other paths for which the object is not initialized, the compiler emits a warning if it cannot prove the uninitialized paths are not executed at run time.
In addition, passing a pointer (or in C++, a reference) to an uninitialized object to a "const"-qualified function argument is also diagnosed by this warning.  (-Wuninitialized is issued for built-in functions known to read the object.)  Annotating the function with attribute "access (none)" indicates that the argument isn't used to access the object and avoids the warning.
These warnings are only possible in optimizing compilation, because otherwise GCC does not keep track of the state of variables.
These warnings are made optional because GCC may not be able to determine when the code is correct in spite of appearing to have an error.  Here is one example of how this can happen:
{ int x; switch (y) { case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; } foo (x); }
If the value of "y" is always 1, 2 or 3, then "x" is always initialized, but GCC doesn't know this. To suppress the warning, you need to provide a default case with assert(0) or similar code.
This option also warns when a non-volatile automatic variable might be changed by a call to "longjmp".  The compiler sees only the calls to "setjmp".  It cannot know where "longjmp" will be called; in fact, a signal handler could call it at any point in the code.  As a result, you may get a warning even when there is in fact no problem because "longjmp" cannot in fact be called at the place that would cause a problem.
Some spurious warnings can be avoided if you declare all the functions you use that never return as "noreturn".
This warning is enabled by -Wall or -Wextra.
-Wunknown-pragmas Warn when a "#pragma" directive is encountered that is not understood by GCC.  If this command-line option is used, warnings are even issued for unknown pragmas in system header files.  This is not the case if the warnings are only enabled by the -Wall command-line option.
-Wno-pragmas Do not warn about misuses of pragmas, such as incorrect parameters, invalid syntax, or conflicts between pragmas.  See also -Wunknown-pragmas.
-Wno-prio-ctor-dtor Do not warn if a priority from 0 to 100 is used for constructor or destructor.  The use of constructor and destructor attributes allow you to assign a priority to the constructor/destructor to control its order of execution before "main" is called or after it returns.  The priority values must be greater than 100 as the compiler reserves priority values between 0--100 for the implementation.
-Wstrict-aliasing This option is only active when -fstrict-aliasing is active.  It warns about code that might break the strict aliasing rules that the compiler is using for optimization.  The warning does not catch all cases, but does attempt to catch the more common pitfalls.  It is included in -Wall.  It is equivalent to -Wstrict-aliasing=3
-Wstrict-aliasing=n This option is only active when -fstrict-aliasing is active.  It warns about code that might break the strict aliasing rules that the compiler is using for optimization.  Higher levels correspond to higher accuracy (fewer false positives).  Higher levels also correspond to more effort, similar to the way -O works. -Wstrict-aliasing is equivalent to -Wstrict-aliasing=3.
Level 1: Most aggressive, quick, least accurate.  Possibly useful when higher levels do not warn but -fstrict-aliasing still breaks the code, as it has very few false negatives.  However, it has many false positives.  Warns for all pointer conversions between possibly incompatible types, even if never dereferenced.  Runs in the front end only.
Level 2: Aggressive, quick, not too precise.  May still have many false positives (not as many as level 1 though), and few false negatives (but possibly more than level 1).  Unlike level 1, it only warns when an address is taken.  Warns about incomplete types.  Runs in the front end only.
Level 3 (default for -Wstrict-aliasing): Should have very few false positives and few false negatives.  Slightly slower than levels 1 or 2 when optimization is enabled.  Takes care of the common pun+dereference pattern in the front end: "*(int*)&some_float".  If optimization is enabled, it also runs in the back end, where it deals with multiple statement cases using flow-sensitive points-to information.  Only warns when the converted pointer is dereferenced. Does not warn about incomplete types.
-Wstrict-overflow -Wstrict-overflow=n This option is only active when signed overflow is undefined.  It warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur.  Note that it does not warn about all cases where the code might overflow: it only warns about cases where the compiler implements some optimization.  Thus this warning depends on the optimization level.
An optimization that assumes that signed overflow does not occur is perfectly safe if the values of the variables involved are such that overflow never does, in fact, occur.  Therefore this warning can easily give a false positive: a warning about code that is not actually a problem.  To help focus on important issues, several warning levels are defined.  No warnings are issued for the use of undefined signed overflow when estimating how many iterations a loop requires, in particular when determining whether a loop will be executed at all.
-Wstrict-overflow=1 Warn about cases that are both questionable and easy to avoid. For example the compiler simplifies "x + 1 > x" to 1.  This level of -Wstrict-overflow is enabled by -Wall; higher levels are not, and must be explicitly requested.
-Wstrict-overflow=2 Also warn about other cases where a comparison is simplified to a constant.  For example: "abs (x) >= 0".  This can only be simplified when signed integer overflow is undefined, because "abs (INT_MIN)" overflows to "INT_MIN", which is less than zero. -Wstrict-overflow (with no level) is the same as -Wstrict-overflow=2.
-Wstrict-overflow=3 Also warn about other cases where a comparison is simplified. For example: "x + 1 > 1" is simplified to "x > 0".