1<html lang="en"> 2<head> 3<title>Warning Options - Using the GNU Compiler Collection (GCC)</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Using the GNU Compiler Collection (GCC)"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Invoking-GCC.html#Invoking-GCC" title="Invoking GCC"> 9<link rel="prev" href="Language-Independent-Options.html#Language-Independent-Options" title="Language Independent Options"> 10<link rel="next" href="Debugging-Options.html#Debugging-Options" title="Debugging Options"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988-2013 Free Software Foundation, Inc. 14 15Permission is granted to copy, distribute and/or modify this document 16under the terms of the GNU Free Documentation License, Version 1.3 or 17any later version published by the Free Software Foundation; with the 18Invariant Sections being ``Funding Free Software'', the Front-Cover 19Texts being (a) (see below), and with the Back-Cover Texts being (b) 20(see below). A copy of the license is included in the section entitled 21``GNU Free Documentation License''. 22 23(a) The FSF's Front-Cover Text is: 24 25 A GNU Manual 26 27(b) The FSF's Back-Cover Text is: 28 29 You have freedom to copy and modify this GNU Manual, like GNU 30 software. Copies published by the Free Software Foundation raise 31 funds for GNU development.--> 32<meta http-equiv="Content-Style-Type" content="text/css"> 33<style type="text/css"><!-- 34 pre.display { font-family:inherit } 35 pre.format { font-family:inherit } 36 pre.smalldisplay { font-family:inherit; font-size:smaller } 37 pre.smallformat { font-family:inherit; font-size:smaller } 38 pre.smallexample { font-size:smaller } 39 pre.smalllisp { font-size:smaller } 40 span.sc { font-variant:small-caps } 41 span.roman { font-family:serif; font-weight:normal; } 42 span.sansserif { font-family:sans-serif; font-weight:normal; } 43--></style> 44<link rel="stylesheet" type="text/css" href="../cs.css"> 45</head> 46<body> 47<div class="node"> 48<a name="Warning-Options"></a> 49<p> 50Next: <a rel="next" accesskey="n" href="Debugging-Options.html#Debugging-Options">Debugging Options</a>, 51Previous: <a rel="previous" accesskey="p" href="Language-Independent-Options.html#Language-Independent-Options">Language Independent Options</a>, 52Up: <a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking-GCC">Invoking GCC</a> 53<hr> 54</div> 55 56<h3 class="section">3.8 Options to Request or Suppress Warnings</h3> 57 58<p><a name="index-options-to-control-warnings-243"></a><a name="index-warning-messages-244"></a><a name="index-messages_002c-warning-245"></a><a name="index-suppressing-warnings-246"></a> 59Warnings are diagnostic messages that report constructions that 60are not inherently erroneous but that are risky or suggest there 61may have been an error. 62 63 <p>The following language-independent options do not enable specific 64warnings but control the kinds of diagnostics produced by GCC. 65 66 67<a name="index-syntax-checking-247"></a> 68<dl><dt><code>-fsyntax-only</code><dd><a name="index-fsyntax_002donly-248"></a>Check the code for syntax errors, but don't do anything beyond that. 69 70 <br><dt><code>-fmax-errors=</code><var>n</var><dd><a name="index-fmax_002derrors-249"></a>Limits the maximum number of error messages to <var>n</var>, at which point 71GCC bails out rather than attempting to continue processing the source 72code. If <var>n</var> is 0 (the default), there is no limit on the number 73of error messages produced. If <samp><span class="option">-Wfatal-errors</span></samp> is also 74specified, then <samp><span class="option">-Wfatal-errors</span></samp> takes precedence over this 75option. 76 77 <br><dt><code>-w</code><dd><a name="index-w-250"></a>Inhibit all warning messages. 78 79 <br><dt><code>-Werror</code><dd><a name="index-Werror-251"></a><a name="index-Wno_002derror-252"></a>Make all warnings into errors. 80 81 <br><dt><code>-Werror=</code><dd><a name="index-Werror_003d-253"></a><a name="index-Wno_002derror_003d-254"></a>Make the specified warning into an error. The specifier for a warning 82is appended; for example <samp><span class="option">-Werror=switch</span></samp> turns the warnings 83controlled by <samp><span class="option">-Wswitch</span></samp> into errors. This switch takes a 84negative form, to be used to negate <samp><span class="option">-Werror</span></samp> for specific 85warnings; for example <samp><span class="option">-Wno-error=switch</span></samp> makes 86<samp><span class="option">-Wswitch</span></samp> warnings not be errors, even when <samp><span class="option">-Werror</span></samp> 87is in effect. 88 89 <p>The warning message for each controllable warning includes the 90option that controls the warning. That option can then be used with 91<samp><span class="option">-Werror=</span></samp> and <samp><span class="option">-Wno-error=</span></samp> as described above. 92(Printing of the option in the warning message can be disabled using the 93<samp><span class="option">-fno-diagnostics-show-option</span></samp> flag.) 94 95 <p>Note that specifying <samp><span class="option">-Werror=</span></samp><var>foo</var> automatically implies 96<samp><span class="option">-W</span></samp><var>foo</var>. However, <samp><span class="option">-Wno-error=</span></samp><var>foo</var> does not 97imply anything. 98 99 <br><dt><code>-Wfatal-errors</code><dd><a name="index-Wfatal_002derrors-255"></a><a name="index-Wno_002dfatal_002derrors-256"></a>This option causes the compiler to abort compilation on the first error 100occurred rather than trying to keep going and printing further error 101messages. 102 103 </dl> 104 105 <p>You can request many specific warnings with options beginning with 106‘<samp><span class="samp">-W</span></samp>’, for example <samp><span class="option">-Wimplicit</span></samp> to request warnings on 107implicit declarations. Each of these specific warning options also 108has a negative form beginning ‘<samp><span class="samp">-Wno-</span></samp>’ to turn off warnings; for 109example, <samp><span class="option">-Wno-implicit</span></samp>. This manual lists only one of the 110two forms, whichever is not the default. For further 111language-specific options also refer to <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options">C++ Dialect Options</a> and 112<a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options">Objective-C and Objective-C++ Dialect Options</a>. 113 114 <p>When an unrecognized warning option is requested (e.g., 115<samp><span class="option">-Wunknown-warning</span></samp>), GCC emits a diagnostic stating 116that the option is not recognized. However, if the <samp><span class="option">-Wno-</span></samp> form 117is used, the behavior is slightly different: no diagnostic is 118produced for <samp><span class="option">-Wno-unknown-warning</span></samp> unless other diagnostics 119are being produced. This allows the use of new <samp><span class="option">-Wno-</span></samp> options 120with old compilers, but if something goes wrong, the compiler 121warns that an unrecognized option is present. 122 123 <dl> 124<dt><code>-Wpedantic</code><dt><code>-pedantic</code><dd><a name="index-pedantic-257"></a><a name="index-Wpedantic-258"></a>Issue all the warnings demanded by strict ISO C and ISO C++; 125reject all programs that use forbidden extensions, and some other 126programs that do not follow ISO C and ISO C++. For ISO C, follows the 127version of the ISO C standard specified by any <samp><span class="option">-std</span></samp> option used. 128 129 <p>Valid ISO C and ISO C++ programs should compile properly with or without 130this option (though a rare few require <samp><span class="option">-ansi</span></samp> or a 131<samp><span class="option">-std</span></samp> option specifying the required version of ISO C). However, 132without this option, certain GNU extensions and traditional C and C++ 133features are supported as well. With this option, they are rejected. 134 135 <p><samp><span class="option">-Wpedantic</span></samp> does not cause warning messages for use of the 136alternate keywords whose names begin and end with ‘<samp><span class="samp">__</span></samp>’. Pedantic 137warnings are also disabled in the expression that follows 138<code>__extension__</code>. However, only system header files should use 139these escape routes; application programs should avoid them. 140See <a href="Alternate-Keywords.html#Alternate-Keywords">Alternate Keywords</a>. 141 142 <p>Some users try to use <samp><span class="option">-Wpedantic</span></samp> to check programs for strict ISO 143C conformance. They soon find that it does not do quite what they want: 144it finds some non-ISO practices, but not all—only those for which 145ISO C <em>requires</em> a diagnostic, and some others for which 146diagnostics have been added. 147 148 <p>A feature to report any failure to conform to ISO C might be useful in 149some instances, but would require considerable additional work and would 150be quite different from <samp><span class="option">-Wpedantic</span></samp>. We don't have plans to 151support such a feature in the near future. 152 153 <p>Where the standard specified with <samp><span class="option">-std</span></samp> represents a GNU 154extended dialect of C, such as ‘<samp><span class="samp">gnu90</span></samp>’ or ‘<samp><span class="samp">gnu99</span></samp>’, there is a 155corresponding <dfn>base standard</dfn>, the version of ISO C on which the GNU 156extended dialect is based. Warnings from <samp><span class="option">-Wpedantic</span></samp> are given 157where they are required by the base standard. (It does not make sense 158for such warnings to be given only for features not in the specified GNU 159C dialect, since by definition the GNU dialects of C include all 160features the compiler supports with the given option, and there would be 161nothing to warn about.) 162 163 <br><dt><code>-pedantic-errors</code><dd><a name="index-pedantic_002derrors-259"></a>Like <samp><span class="option">-Wpedantic</span></samp>, except that errors are produced rather than 164warnings. 165 166 <br><dt><code>-Wall</code><dd><a name="index-Wall-260"></a><a name="index-Wno_002dall-261"></a>This enables all the warnings about constructions that some users 167consider questionable, and that are easy to avoid (or modify to 168prevent the warning), even in conjunction with macros. This also 169enables some language-specific warnings described in <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options">C++ Dialect Options</a> and <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options">Objective-C and Objective-C++ Dialect Options</a>. 170 171 <p><samp><span class="option">-Wall</span></samp> turns on the following warning flags: 172 173 <pre class="smallexample"> -Waddress 174 -Warray-bounds <span class="roman">(only with</span> <samp><span class="option">-O2</span></samp><span class="roman">)</span> 175 -Wc++11-compat 176 -Wchar-subscripts 177 -Wenum-compare <span class="roman">(in C/ObjC; this is on by default in C++)</span> 178 -Wimplicit-int <span class="roman">(C and Objective-C only)</span> 179 -Wimplicit-function-declaration <span class="roman">(C and Objective-C only)</span> 180 -Wcomment 181 -Wformat 182 -Wmain <span class="roman">(only for C/ObjC and unless</span> <samp><span class="option">-ffreestanding</span></samp><span class="roman">)</span> 183 -Wmaybe-uninitialized 184 -Wmissing-braces <span class="roman">(only for C/ObjC)</span> 185 -Wnonnull 186 -Wparentheses 187 -Wpointer-sign 188 -Wreorder 189 -Wreturn-type 190 -Wsequence-point 191 -Wsign-compare <span class="roman">(only in C++)</span> 192 -Wstrict-aliasing 193 -Wstrict-overflow=1 194 -Wswitch 195 -Wtrigraphs 196 -Wuninitialized 197 -Wunknown-pragmas 198 -Wunused-function 199 -Wunused-label 200 -Wunused-value 201 -Wunused-variable 202 -Wvolatile-register-var 203 204</pre> 205 <p>Note that some warning flags are not implied by <samp><span class="option">-Wall</span></samp>. Some of 206them warn about constructions that users generally do not consider 207questionable, but which occasionally you might wish to check for; 208others warn about constructions that are necessary or hard to avoid in 209some cases, and there is no simple way to modify the code to suppress 210the warning. Some of them are enabled by <samp><span class="option">-Wextra</span></samp> but many of 211them must be enabled individually. 212 213 <br><dt><code>-Wextra</code><dd><a name="index-W-262"></a><a name="index-Wextra-263"></a><a name="index-Wno_002dextra-264"></a>This enables some extra warning flags that are not enabled by 214<samp><span class="option">-Wall</span></samp>. (This option used to be called <samp><span class="option">-W</span></samp>. The older 215name is still supported, but the newer name is more descriptive.) 216 217 <pre class="smallexample"> -Wclobbered 218 -Wempty-body 219 -Wignored-qualifiers 220 -Wmissing-field-initializers 221 -Wmissing-parameter-type <span class="roman">(C only)</span> 222 -Wold-style-declaration <span class="roman">(C only)</span> 223 -Woverride-init 224 -Wsign-compare 225 -Wtype-limits 226 -Wuninitialized 227 -Wunused-parameter <span class="roman">(only with</span> <samp><span class="option">-Wunused</span></samp> <span class="roman">or</span> <samp><span class="option">-Wall</span></samp><span class="roman">)</span> 228 -Wunused-but-set-parameter <span class="roman">(only with</span> <samp><span class="option">-Wunused</span></samp> <span class="roman">or</span> <samp><span class="option">-Wall</span></samp><span class="roman">)</span> 229 230</pre> 231 <p>The option <samp><span class="option">-Wextra</span></samp> also prints warning messages for the 232following cases: 233 234 <ul> 235<li>A pointer is compared against integer zero with ‘<samp><span class="samp"><</span></samp>’, ‘<samp><span class="samp"><=</span></samp>’, 236‘<samp><span class="samp">></span></samp>’, or ‘<samp><span class="samp">>=</span></samp>’. 237 238 <li>(C++ only) An enumerator and a non-enumerator both appear in a 239conditional expression. 240 241 <li>(C++ only) Ambiguous virtual bases. 242 243 <li>(C++ only) Subscripting an array that has been declared ‘<samp><span class="samp">register</span></samp>’. 244 245 <li>(C++ only) Taking the address of a variable that has been declared 246‘<samp><span class="samp">register</span></samp>’. 247 248 <li>(C++ only) A base class is not initialized in a derived class's copy 249constructor. 250 251 </ul> 252 253 <br><dt><code>-Wchar-subscripts</code><dd><a name="index-Wchar_002dsubscripts-265"></a><a name="index-Wno_002dchar_002dsubscripts-266"></a>Warn if an array subscript has type <code>char</code>. This is a common cause 254of error, as programmers often forget that this type is signed on some 255machines. 256This warning is enabled by <samp><span class="option">-Wall</span></samp>. 257 258 <br><dt><code>-Wcomment</code><dd><a name="index-Wcomment-267"></a><a name="index-Wno_002dcomment-268"></a>Warn whenever a comment-start sequence ‘<samp><span class="samp">/*</span></samp>’ appears in a ‘<samp><span class="samp">/*</span></samp>’ 259comment, or whenever a Backslash-Newline appears in a ‘<samp><span class="samp">//</span></samp>’ comment. 260This warning is enabled by <samp><span class="option">-Wall</span></samp>. 261 262 <br><dt><code>-Wno-coverage-mismatch</code><dd><a name="index-Wno_002dcoverage_002dmismatch-269"></a>Warn if feedback profiles do not match when using the 263<samp><span class="option">-fprofile-use</span></samp> option. 264If a source file is changed between compiling with <samp><span class="option">-fprofile-gen</span></samp> and 265with <samp><span class="option">-fprofile-use</span></samp>, the files with the profile feedback can fail 266to match the source file and GCC cannot use the profile feedback 267information. By default, this warning is enabled and is treated as an 268error. <samp><span class="option">-Wno-coverage-mismatch</span></samp> can be used to disable the 269warning or <samp><span class="option">-Wno-error=coverage-mismatch</span></samp> can be used to 270disable the error. Disabling the error for this warning can result in 271poorly optimized code and is useful only in the 272case of very minor changes such as bug fixes to an existing code-base. 273Completely disabling the warning is not recommended. 274 275 <br><dt><code>-Wno-cpp</code><dd><span class="roman">(C, Objective-C, C++, Objective-C++ and Fortran only)</span> 276 277 <p>Suppress warning messages emitted by <code>#warning</code> directives. 278 279 <br><dt><code>-Wdouble-promotion </code><span class="roman">(C, C++, Objective-C and Objective-C++ only)</span><dd><a name="index-Wdouble_002dpromotion-270"></a><a name="index-Wno_002ddouble_002dpromotion-271"></a>Give a warning when a value of type <code>float</code> is implicitly 280promoted to <code>double</code>. CPUs with a 32-bit “single-precision” 281floating-point unit implement <code>float</code> in hardware, but emulate 282<code>double</code> in software. On such a machine, doing computations 283using <code>double</code> values is much more expensive because of the 284overhead required for software emulation. 285 286 <p>It is easy to accidentally do computations with <code>double</code> because 287floating-point literals are implicitly of type <code>double</code>. For 288example, in: 289 <pre class="smallexample"> float area(float radius) 290 { 291 return 3.14159 * radius * radius; 292 } 293</pre> 294 <p>the compiler performs the entire computation with <code>double</code> 295because the floating-point literal is a <code>double</code>. 296 297 <br><dt><code>-Wformat</code><dt><code>-Wformat=</code><var>n</var><dd><a name="index-Wformat-272"></a><a name="index-Wno_002dformat-273"></a><a name="index-ffreestanding-274"></a><a name="index-fno_002dbuiltin-275"></a><a name="index-Wformat_003d-276"></a>Check calls to <code>printf</code> and <code>scanf</code>, etc., to make sure that 298the arguments supplied have types appropriate to the format string 299specified, and that the conversions specified in the format string make 300sense. This includes standard functions, and others specified by format 301attributes (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>), in the <code>printf</code>, 302<code>scanf</code>, <code>strftime</code> and <code>strfmon</code> (an X/Open extension, 303not in the C standard) families (or other target-specific families). 304Which functions are checked without format attributes having been 305specified depends on the standard version selected, and such checks of 306functions without the attribute specified are disabled by 307<samp><span class="option">-ffreestanding</span></samp> or <samp><span class="option">-fno-builtin</span></samp>. 308 309 <p>The formats are checked against the format features supported by GNU 310libc version 2.2. These include all ISO C90 and C99 features, as well 311as features from the Single Unix Specification and some BSD and GNU 312extensions. Other library implementations may not support all these 313features; GCC does not support warning about features that go beyond a 314particular library's limitations. However, if <samp><span class="option">-Wpedantic</span></samp> is used 315with <samp><span class="option">-Wformat</span></samp>, warnings are given about format features not 316in the selected standard version (but not for <code>strfmon</code> formats, 317since those are not in any version of the C standard). See <a href="C-Dialect-Options.html#C-Dialect-Options">Options Controlling C Dialect</a>. 318 319 <dl> 320<dt><code>-Wformat=1</code><dt><code>-Wformat</code><dd>Option <samp><span class="option">-Wformat</span></samp> is equivalent to <samp><span class="option">-Wformat=1</span></samp>, and 321<samp><span class="option">-Wno-format</span></samp> is equivalent to <samp><span class="option">-Wformat=0</span></samp>. Since 322<samp><span class="option">-Wformat</span></samp> also checks for null format arguments for several 323functions, <samp><span class="option">-Wformat</span></samp> also implies <samp><span class="option">-Wnonnull</span></samp>. Some 324aspects of this level of format checking can be disabled by the 325options: <samp><span class="option">-Wno-format-contains-nul</span></samp>, 326<samp><span class="option">-Wno-format-extra-args</span></samp>, and <samp><span class="option">-Wno-format-zero-length</span></samp>. 327<samp><span class="option">-Wformat</span></samp> is enabled by <samp><span class="option">-Wall</span></samp>. 328 329 <br><dt><code>-Wno-format-contains-nul</code><dd><a name="index-Wno_002dformat_002dcontains_002dnul-277"></a><a name="index-Wformat_002dcontains_002dnul-278"></a>If <samp><span class="option">-Wformat</span></samp> is specified, do not warn about format strings that 330contain NUL bytes. 331 332 <br><dt><code>-Wno-format-extra-args</code><dd><a name="index-Wno_002dformat_002dextra_002dargs-279"></a><a name="index-Wformat_002dextra_002dargs-280"></a>If <samp><span class="option">-Wformat</span></samp> is specified, do not warn about excess arguments to a 333<code>printf</code> or <code>scanf</code> format function. The C standard specifies 334that such arguments are ignored. 335 336 <p>Where the unused arguments lie between used arguments that are 337specified with ‘<samp><span class="samp">$</span></samp>’ operand number specifications, normally 338warnings are still given, since the implementation could not know what 339type to pass to <code>va_arg</code> to skip the unused arguments. However, 340in the case of <code>scanf</code> formats, this option suppresses the 341warning if the unused arguments are all pointers, since the Single 342Unix Specification says that such unused arguments are allowed. 343 344 <br><dt><code>-Wno-format-zero-length</code><dd><a name="index-Wno_002dformat_002dzero_002dlength-281"></a><a name="index-Wformat_002dzero_002dlength-282"></a>If <samp><span class="option">-Wformat</span></samp> is specified, do not warn about zero-length formats. 345The C standard specifies that zero-length formats are allowed. 346 347 <br><dt><code>-Wformat=2</code><dd>Enable <samp><span class="option">-Wformat</span></samp> plus additional format checks. Currently 348equivalent to <samp><span class="option">-Wformat -Wformat-nonliteral -Wformat-security 349-Wformat-y2k</span></samp>. 350 351 <br><dt><code>-Wformat-nonliteral</code><dd><a name="index-Wformat_002dnonliteral-283"></a><a name="index-Wno_002dformat_002dnonliteral-284"></a>If <samp><span class="option">-Wformat</span></samp> is specified, also warn if the format string is not a 352string literal and so cannot be checked, unless the format function 353takes its format arguments as a <code>va_list</code>. 354 355 <br><dt><code>-Wformat-security</code><dd><a name="index-Wformat_002dsecurity-285"></a><a name="index-Wno_002dformat_002dsecurity-286"></a>If <samp><span class="option">-Wformat</span></samp> is specified, also warn about uses of format 356functions that represent possible security problems. At present, this 357warns about calls to <code>printf</code> and <code>scanf</code> functions where the 358format string is not a string literal and there are no format arguments, 359as in <code>printf (foo);</code>. This may be a security hole if the format 360string came from untrusted input and contains ‘<samp><span class="samp">%n</span></samp>’. (This is 361currently a subset of what <samp><span class="option">-Wformat-nonliteral</span></samp> warns about, but 362in future warnings may be added to <samp><span class="option">-Wformat-security</span></samp> that are not 363included in <samp><span class="option">-Wformat-nonliteral</span></samp>.) 364 365 <br><dt><code>-Wformat-y2k</code><dd><a name="index-Wformat_002dy2k-287"></a><a name="index-Wno_002dformat_002dy2k-288"></a>If <samp><span class="option">-Wformat</span></samp> is specified, also warn about <code>strftime</code> 366formats that may yield only a two-digit year. 367</dl> 368 369 <br><dt><code>-Wnonnull</code><dd><a name="index-Wnonnull-289"></a><a name="index-Wno_002dnonnull-290"></a>Warn about passing a null pointer for arguments marked as 370requiring a non-null value by the <code>nonnull</code> function attribute. 371 372 <p><samp><span class="option">-Wnonnull</span></samp> is included in <samp><span class="option">-Wall</span></samp> and <samp><span class="option">-Wformat</span></samp>. It 373can be disabled with the <samp><span class="option">-Wno-nonnull</span></samp> option. 374 375 <br><dt><code>-Winit-self </code><span class="roman">(C, C++, Objective-C and Objective-C++ only)</span><dd><a name="index-Winit_002dself-291"></a><a name="index-Wno_002dinit_002dself-292"></a>Warn about uninitialized variables that are initialized with themselves. 376Note this option can only be used with the <samp><span class="option">-Wuninitialized</span></samp> option. 377 378 <p>For example, GCC warns about <code>i</code> being uninitialized in the 379following snippet only when <samp><span class="option">-Winit-self</span></samp> has been specified: 380 <pre class="smallexample"> int f() 381 { 382 int i = i; 383 return i; 384 } 385</pre> 386 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp> in C++. 387 388 <br><dt><code>-Wimplicit-int </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wimplicit_002dint-293"></a><a name="index-Wno_002dimplicit_002dint-294"></a>Warn when a declaration does not specify a type. 389This warning is enabled by <samp><span class="option">-Wall</span></samp>. 390 391 <br><dt><code>-Wimplicit-function-declaration </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wimplicit_002dfunction_002ddeclaration-295"></a><a name="index-Wno_002dimplicit_002dfunction_002ddeclaration-296"></a>Give a warning whenever a function is used before being declared. In 392C99 mode (<samp><span class="option">-std=c99</span></samp> or <samp><span class="option">-std=gnu99</span></samp>), this warning is 393enabled by default and it is made into an error by 394<samp><span class="option">-pedantic-errors</span></samp>. This warning is also enabled by 395<samp><span class="option">-Wall</span></samp>. 396 397 <br><dt><code>-Wimplicit </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wimplicit-297"></a><a name="index-Wno_002dimplicit-298"></a>Same as <samp><span class="option">-Wimplicit-int</span></samp> and <samp><span class="option">-Wimplicit-function-declaration</span></samp>. 398This warning is enabled by <samp><span class="option">-Wall</span></samp>. 399 400 <br><dt><code>-Wignored-qualifiers </code><span class="roman">(C and C++ only)</span><dd><a name="index-Wignored_002dqualifiers-299"></a><a name="index-Wno_002dignored_002dqualifiers-300"></a>Warn if the return type of a function has a type qualifier 401such as <code>const</code>. For ISO C such a type qualifier has no effect, 402since the value returned by a function is not an lvalue. 403For C++, the warning is only emitted for scalar types or <code>void</code>. 404ISO C prohibits qualified <code>void</code> return types on function 405definitions, so such return types always receive a warning 406even without this option. 407 408 <p>This warning is also enabled by <samp><span class="option">-Wextra</span></samp>. 409 410 <br><dt><code>-Wmain</code><dd><a name="index-Wmain-301"></a><a name="index-Wno_002dmain-302"></a>Warn if the type of ‘<samp><span class="samp">main</span></samp>’ is suspicious. ‘<samp><span class="samp">main</span></samp>’ should be 411a function with external linkage, returning int, taking either zero 412arguments, two, or three arguments of appropriate types. This warning 413is enabled by default in C++ and is enabled by either <samp><span class="option">-Wall</span></samp> 414or <samp><span class="option">-Wpedantic</span></samp>. 415 416 <br><dt><code>-Wmissing-braces</code><dd><a name="index-Wmissing_002dbraces-303"></a><a name="index-Wno_002dmissing_002dbraces-304"></a>Warn if an aggregate or union initializer is not fully bracketed. In 417the following example, the initializer for ‘<samp><span class="samp">a</span></samp>’ is not fully 418bracketed, but that for ‘<samp><span class="samp">b</span></samp>’ is fully bracketed. This warning is 419enabled by <samp><span class="option">-Wall</span></samp> in C. 420 421 <pre class="smallexample"> int a[2][2] = { 0, 1, 2, 3 }; 422 int b[2][2] = { { 0, 1 }, { 2, 3 } }; 423</pre> 424 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp>. 425 426 <br><dt><code>-Wmissing-include-dirs </code><span class="roman">(C, C++, Objective-C and Objective-C++ only)</span><dd><a name="index-Wmissing_002dinclude_002ddirs-305"></a><a name="index-Wno_002dmissing_002dinclude_002ddirs-306"></a>Warn if a user-supplied include directory does not exist. 427 428 <br><dt><code>-Wparentheses</code><dd><a name="index-Wparentheses-307"></a><a name="index-Wno_002dparentheses-308"></a>Warn if parentheses are omitted in certain contexts, such 429as when there is an assignment in a context where a truth value 430is expected, or when operators are nested whose precedence people 431often get confused about. 432 433 <p>Also warn if a comparison like ‘<samp><span class="samp">x<=y<=z</span></samp>’ appears; this is 434equivalent to ‘<samp><span class="samp">(x<=y ? 1 : 0) <= z</span></samp>’, which is a different 435interpretation from that of ordinary mathematical notation. 436 437 <p>Also warn about constructions where there may be confusion to which 438<code>if</code> statement an <code>else</code> branch belongs. Here is an example of 439such a case: 440 441 <pre class="smallexample"> { 442 if (a) 443 if (b) 444 foo (); 445 else 446 bar (); 447 } 448</pre> 449 <p>In C/C++, every <code>else</code> branch belongs to the innermost possible 450<code>if</code> statement, which in this example is <code>if (b)</code>. This is 451often not what the programmer expected, as illustrated in the above 452example by indentation the programmer chose. When there is the 453potential for this confusion, GCC issues a warning when this flag 454is specified. To eliminate the warning, add explicit braces around 455the innermost <code>if</code> statement so there is no way the <code>else</code> 456can belong to the enclosing <code>if</code>. The resulting code 457looks like this: 458 459 <pre class="smallexample"> { 460 if (a) 461 { 462 if (b) 463 foo (); 464 else 465 bar (); 466 } 467 } 468</pre> 469 <p>Also warn for dangerous uses of the GNU extension to 470<code>?:</code> with omitted middle operand. When the condition 471in the <code>?</code>: operator is a boolean expression, the omitted value is 472always 1. Often programmers expect it to be a value computed 473inside the conditional expression instead. 474 475 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp>. 476 477 <br><dt><code>-Wsequence-point</code><dd><a name="index-Wsequence_002dpoint-309"></a><a name="index-Wno_002dsequence_002dpoint-310"></a>Warn about code that may have undefined semantics because of violations 478of sequence point rules in the C and C++ standards. 479 480 <p>The C and C++ standards define the order in which expressions in a C/C++ 481program are evaluated in terms of <dfn>sequence points</dfn>, which represent 482a partial ordering between the execution of parts of the program: those 483executed before the sequence point, and those executed after it. These 484occur after the evaluation of a full expression (one which is not part 485of a larger expression), after the evaluation of the first operand of a 486<code>&&</code>, <code>||</code>, <code>? :</code> or <code>,</code> (comma) operator, before a 487function is called (but after the evaluation of its arguments and the 488expression denoting the called function), and in certain other places. 489Other than as expressed by the sequence point rules, the order of 490evaluation of subexpressions of an expression is not specified. All 491these rules describe only a partial order rather than a total order, 492since, for example, if two functions are called within one expression 493with no sequence point between them, the order in which the functions 494are called is not specified. However, the standards committee have 495ruled that function calls do not overlap. 496 497 <p>It is not specified when between sequence points modifications to the 498values of objects take effect. Programs whose behavior depends on this 499have undefined behavior; the C and C++ standards specify that “Between 500the previous and next sequence point an object shall have its stored 501value modified at most once by the evaluation of an expression. 502Furthermore, the prior value shall be read only to determine the value 503to be stored.”. If a program breaks these rules, the results on any 504particular implementation are entirely unpredictable. 505 506 <p>Examples of code with undefined behavior are <code>a = a++;</code>, <code>a[n] 507= b[n++]</code> and <code>a[i++] = i;</code>. Some more complicated cases are not 508diagnosed by this option, and it may give an occasional false positive 509result, but in general it has been found fairly effective at detecting 510this sort of problem in programs. 511 512 <p>The standard is worded confusingly, therefore there is some debate 513over the precise meaning of the sequence point rules in subtle cases. 514Links to discussions of the problem, including proposed formal 515definitions, may be found on the GCC readings page, at 516<a href="http://gcc.gnu.org/readings.html">http://gcc.gnu.org/readings.html</a>. 517 518 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp> for C and C++. 519 520 <br><dt><code>-Wno-return-local-addr</code><dd><a name="index-Wno_002dreturn_002dlocal_002daddr-311"></a><a name="index-Wreturn_002dlocal_002daddr-312"></a>Do not warn about returning a pointer (or in C++, a reference) to a 521variable that goes out of scope after the function returns. 522 523 <br><dt><code>-Wreturn-type</code><dd><a name="index-Wreturn_002dtype-313"></a><a name="index-Wno_002dreturn_002dtype-314"></a>Warn whenever a function is defined with a return type that defaults 524to <code>int</code>. Also warn about any <code>return</code> statement with no 525return value in a function whose return type is not <code>void</code> 526(falling off the end of the function body is considered returning 527without a value), and about a <code>return</code> statement with an 528expression in a function whose return type is <code>void</code>. 529 530 <p>For C++, a function without return type always produces a diagnostic 531message, even when <samp><span class="option">-Wno-return-type</span></samp> is specified. The only 532exceptions are ‘<samp><span class="samp">main</span></samp>’ and functions defined in system headers. 533 534 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp>. 535 536 <br><dt><code>-Wswitch</code><dd><a name="index-Wswitch-315"></a><a name="index-Wno_002dswitch-316"></a>Warn whenever a <code>switch</code> statement has an index of enumerated type 537and lacks a <code>case</code> for one or more of the named codes of that 538enumeration. (The presence of a <code>default</code> label prevents this 539warning.) <code>case</code> labels outside the enumeration range also 540provoke warnings when this option is used (even if there is a 541<code>default</code> label). 542This warning is enabled by <samp><span class="option">-Wall</span></samp>. 543 544 <br><dt><code>-Wswitch-default</code><dd><a name="index-Wswitch_002ddefault-317"></a><a name="index-Wno_002dswitch_002ddefault-318"></a>Warn whenever a <code>switch</code> statement does not have a <code>default</code> 545case. 546 547 <br><dt><code>-Wswitch-enum</code><dd><a name="index-Wswitch_002denum-319"></a><a name="index-Wno_002dswitch_002denum-320"></a>Warn whenever a <code>switch</code> statement has an index of enumerated type 548and lacks a <code>case</code> for one or more of the named codes of that 549enumeration. <code>case</code> labels outside the enumeration range also 550provoke warnings when this option is used. The only difference 551between <samp><span class="option">-Wswitch</span></samp> and this option is that this option gives a 552warning about an omitted enumeration code even if there is a 553<code>default</code> label. 554 555 <br><dt><code>-Wsync-nand </code><span class="roman">(C and C++ only)</span><dd><a name="index-Wsync_002dnand-321"></a><a name="index-Wno_002dsync_002dnand-322"></a>Warn when <code>__sync_fetch_and_nand</code> and <code>__sync_nand_and_fetch</code> 556built-in functions are used. These functions changed semantics in GCC 4.4. 557 558 <br><dt><code>-Wtrigraphs</code><dd><a name="index-Wtrigraphs-323"></a><a name="index-Wno_002dtrigraphs-324"></a>Warn if any trigraphs are encountered that might change the meaning of 559the program (trigraphs within comments are not warned about). 560This warning is enabled by <samp><span class="option">-Wall</span></samp>. 561 562 <br><dt><code>-Wunused-but-set-parameter</code><dd><a name="index-Wunused_002dbut_002dset_002dparameter-325"></a><a name="index-Wno_002dunused_002dbut_002dset_002dparameter-326"></a>Warn whenever a function parameter is assigned to, but otherwise unused 563(aside from its declaration). 564 565 <p>To suppress this warning use the ‘<samp><span class="samp">unused</span></samp>’ attribute 566(see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>). 567 568 <p>This warning is also enabled by <samp><span class="option">-Wunused</span></samp> together with 569<samp><span class="option">-Wextra</span></samp>. 570 571 <br><dt><code>-Wunused-but-set-variable</code><dd><a name="index-Wunused_002dbut_002dset_002dvariable-327"></a><a name="index-Wno_002dunused_002dbut_002dset_002dvariable-328"></a>Warn whenever a local variable is assigned to, but otherwise unused 572(aside from its declaration). 573This warning is enabled by <samp><span class="option">-Wall</span></samp>. 574 575 <p>To suppress this warning use the ‘<samp><span class="samp">unused</span></samp>’ attribute 576(see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>). 577 578 <p>This warning is also enabled by <samp><span class="option">-Wunused</span></samp>, which is enabled 579by <samp><span class="option">-Wall</span></samp>. 580 581 <br><dt><code>-Wunused-function</code><dd><a name="index-Wunused_002dfunction-329"></a><a name="index-Wno_002dunused_002dfunction-330"></a>Warn whenever a static function is declared but not defined or a 582non-inline static function is unused. 583This warning is enabled by <samp><span class="option">-Wall</span></samp>. 584 585 <br><dt><code>-Wunused-label</code><dd><a name="index-Wunused_002dlabel-331"></a><a name="index-Wno_002dunused_002dlabel-332"></a>Warn whenever a label is declared but not used. 586This warning is enabled by <samp><span class="option">-Wall</span></samp>. 587 588 <p>To suppress this warning use the ‘<samp><span class="samp">unused</span></samp>’ attribute 589(see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>). 590 591 <br><dt><code>-Wunused-local-typedefs </code><span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span><dd><a name="index-Wunused_002dlocal_002dtypedefs-333"></a>Warn when a typedef locally defined in a function is not used. 592This warning is enabled by <samp><span class="option">-Wall</span></samp>. 593 594 <br><dt><code>-Wunused-parameter</code><dd><a name="index-Wunused_002dparameter-334"></a><a name="index-Wno_002dunused_002dparameter-335"></a>Warn whenever a function parameter is unused aside from its declaration. 595 596 <p>To suppress this warning use the ‘<samp><span class="samp">unused</span></samp>’ attribute 597(see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>). 598 599 <br><dt><code>-Wno-unused-result</code><dd><a name="index-Wunused_002dresult-336"></a><a name="index-Wno_002dunused_002dresult-337"></a>Do not warn if a caller of a function marked with attribute 600<code>warn_unused_result</code> (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>) does not use 601its return value. The default is <samp><span class="option">-Wunused-result</span></samp>. 602 603 <br><dt><code>-Wunused-variable</code><dd><a name="index-Wunused_002dvariable-338"></a><a name="index-Wno_002dunused_002dvariable-339"></a>Warn whenever a local variable or non-constant static variable is unused 604aside from its declaration. 605This warning is enabled by <samp><span class="option">-Wall</span></samp>. 606 607 <p>To suppress this warning use the ‘<samp><span class="samp">unused</span></samp>’ attribute 608(see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>). 609 610 <br><dt><code>-Wunused-value</code><dd><a name="index-Wunused_002dvalue-340"></a><a name="index-Wno_002dunused_002dvalue-341"></a>Warn whenever a statement computes a result that is explicitly not 611used. To suppress this warning cast the unused expression to 612‘<samp><span class="samp">void</span></samp>’. This includes an expression-statement or the left-hand 613side of a comma expression that contains no side effects. For example, 614an expression such as ‘<samp><span class="samp">x[i,j]</span></samp>’ causes a warning, while 615‘<samp><span class="samp">x[(void)i,j]</span></samp>’ does not. 616 617 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp>. 618 619 <br><dt><code>-Wunused</code><dd><a name="index-Wunused-342"></a><a name="index-Wno_002dunused-343"></a>All the above <samp><span class="option">-Wunused</span></samp> options combined. 620 621 <p>In order to get a warning about an unused function parameter, you must 622either specify <samp><span class="option">-Wextra -Wunused</span></samp> (note that <samp><span class="option">-Wall</span></samp> implies 623<samp><span class="option">-Wunused</span></samp>), or separately specify <samp><span class="option">-Wunused-parameter</span></samp>. 624 625 <br><dt><code>-Wuninitialized</code><dd><a name="index-Wuninitialized-344"></a><a name="index-Wno_002duninitialized-345"></a>Warn if an automatic variable is used without first being initialized 626or if a variable may be clobbered by a <code>setjmp</code> call. In C++, 627warn if a non-static reference or non-static ‘<samp><span class="samp">const</span></samp>’ member 628appears in a class without constructors. 629 630 <p>If you want to warn about code that uses the uninitialized value of the 631variable in its own initializer, use the <samp><span class="option">-Winit-self</span></samp> option. 632 633 <p>These warnings occur for individual uninitialized or clobbered 634elements of structure, union or array variables as well as for 635variables that are uninitialized or clobbered as a whole. They do 636not occur for variables or elements declared <code>volatile</code>. Because 637these warnings depend on optimization, the exact variables or elements 638for which there are warnings depends on the precise optimization 639options and version of GCC used. 640 641 <p>Note that there may be no warning about a variable that is used only 642to compute a value that itself is never used, because such 643computations may be deleted by data flow analysis before the warnings 644are printed. 645 646 <br><dt><code>-Wmaybe-uninitialized</code><dd><a name="index-Wmaybe_002duninitialized-346"></a><a name="index-Wno_002dmaybe_002duninitialized-347"></a>For an automatic variable, if there exists a path from the function 647entry to a use of the variable that is initialized, but there exist 648some other paths for which the variable is not initialized, the compiler 649emits a warning if it cannot prove the uninitialized paths are not 650executed at run time. These warnings are made optional because GCC is 651not smart enough to see all the reasons why the code might be correct 652in spite of appearing to have an error. Here is one example of how 653this can happen: 654 655 <pre class="smallexample"> { 656 int x; 657 switch (y) 658 { 659 case 1: x = 1; 660 break; 661 case 2: x = 4; 662 break; 663 case 3: x = 5; 664 } 665 foo (x); 666 } 667</pre> 668 <p class="noindent">If the value of <code>y</code> is always 1, 2 or 3, then <code>x</code> is 669always initialized, but GCC doesn't know this. To suppress the 670warning, you need to provide a default case with assert(0) or 671similar code. 672 673 <p><a name="index-g_t_0040code_007blongjmp_007d-warnings-348"></a>This option also warns when a non-volatile automatic variable might be 674changed by a call to <code>longjmp</code>. These warnings as well are possible 675only in optimizing compilation. 676 677 <p>The compiler sees only the calls to <code>setjmp</code>. It cannot know 678where <code>longjmp</code> will be called; in fact, a signal handler could 679call it at any point in the code. As a result, you may get a warning 680even when there is in fact no problem because <code>longjmp</code> cannot 681in fact be called at the place that would cause a problem. 682 683 <p>Some spurious warnings can be avoided if you declare all the functions 684you use that never return as <code>noreturn</code>. See <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>. 685 686 <p>This warning is enabled by <samp><span class="option">-Wall</span></samp> or <samp><span class="option">-Wextra</span></samp>. 687 688 <br><dt><code>-Wunknown-pragmas</code><dd><a name="index-Wunknown_002dpragmas-349"></a><a name="index-Wno_002dunknown_002dpragmas-350"></a><a name="index-warning-for-unknown-pragmas-351"></a><a name="index-unknown-pragmas_002c-warning-352"></a><a name="index-pragmas_002c-warning-of-unknown-353"></a>Warn when a <code>#pragma</code> directive is encountered that is not understood by 689GCC. If this command-line option is used, warnings are even issued 690for unknown pragmas in system header files. This is not the case if 691the warnings are only enabled by the <samp><span class="option">-Wall</span></samp> command-line option. 692 693 <br><dt><code>-Wno-pragmas</code><dd><a name="index-Wno_002dpragmas-354"></a><a name="index-Wpragmas-355"></a>Do not warn about misuses of pragmas, such as incorrect parameters, 694invalid syntax, or conflicts between pragmas. See also 695<samp><span class="option">-Wunknown-pragmas</span></samp>. 696 697 <br><dt><code>-Wstrict-aliasing</code><dd><a name="index-Wstrict_002daliasing-356"></a><a name="index-Wno_002dstrict_002daliasing-357"></a>This option is only active when <samp><span class="option">-fstrict-aliasing</span></samp> is active. 698It warns about code that might break the strict aliasing rules that the 699compiler is using for optimization. The warning does not catch all 700cases, but does attempt to catch the more common pitfalls. It is 701included in <samp><span class="option">-Wall</span></samp>. 702It is equivalent to <samp><span class="option">-Wstrict-aliasing=3</span></samp> 703 704 <br><dt><code>-Wstrict-aliasing=n</code><dd><a name="index-Wstrict_002daliasing_003dn-358"></a>This option is only active when <samp><span class="option">-fstrict-aliasing</span></samp> is active. 705It warns about code that might break the strict aliasing rules that the 706compiler is using for optimization. 707Higher levels correspond to higher accuracy (fewer false positives). 708Higher levels also correspond to more effort, similar to the way <samp><span class="option">-O</span></samp> 709works. 710<samp><span class="option">-Wstrict-aliasing</span></samp> is equivalent to <samp><span class="option">-Wstrict-aliasing=3</span></samp>. 711 712 <p>Level 1: Most aggressive, quick, least accurate. 713Possibly useful when higher levels 714do not warn but <samp><span class="option">-fstrict-aliasing</span></samp> still breaks the code, as it has very few 715false negatives. However, it has many false positives. 716Warns for all pointer conversions between possibly incompatible types, 717even if never dereferenced. Runs in the front end only. 718 719 <p>Level 2: Aggressive, quick, not too precise. 720May still have many false positives (not as many as level 1 though), 721and few false negatives (but possibly more than level 1). 722Unlike level 1, it only warns when an address is taken. Warns about 723incomplete types. Runs in the front end only. 724 725 <p>Level 3 (default for <samp><span class="option">-Wstrict-aliasing</span></samp>): 726Should have very few false positives and few false 727negatives. Slightly slower than levels 1 or 2 when optimization is enabled. 728Takes care of the common pun+dereference pattern in the front end: 729<code>*(int*)&some_float</code>. 730If optimization is enabled, it also runs in the back end, where it deals 731with multiple statement cases using flow-sensitive points-to information. 732Only warns when the converted pointer is dereferenced. 733Does not warn about incomplete types. 734 735 <br><dt><code>-Wstrict-overflow</code><dt><code>-Wstrict-overflow=</code><var>n</var><dd><a name="index-Wstrict_002doverflow-359"></a><a name="index-Wno_002dstrict_002doverflow-360"></a>This option is only active when <samp><span class="option">-fstrict-overflow</span></samp> is active. 736It warns about cases where the compiler optimizes based on the 737assumption that signed overflow does not occur. Note that it does not 738warn about all cases where the code might overflow: it only warns 739about cases where the compiler implements some optimization. Thus 740this warning depends on the optimization level. 741 742 <p>An optimization that assumes that signed overflow does not occur is 743perfectly safe if the values of the variables involved are such that 744overflow never does, in fact, occur. Therefore this warning can 745easily give a false positive: a warning about code that is not 746actually a problem. To help focus on important issues, several 747warning levels are defined. No warnings are issued for the use of 748undefined signed overflow when estimating how many iterations a loop 749requires, in particular when determining whether a loop will be 750executed at all. 751 752 <dl> 753<dt><code>-Wstrict-overflow=1</code><dd>Warn about cases that are both questionable and easy to avoid. For 754example, with <samp><span class="option">-fstrict-overflow</span></samp>, the compiler simplifies 755<code>x + 1 > x</code> to <code>1</code>. This level of 756<samp><span class="option">-Wstrict-overflow</span></samp> is enabled by <samp><span class="option">-Wall</span></samp>; higher levels 757are not, and must be explicitly requested. 758 759 <br><dt><code>-Wstrict-overflow=2</code><dd>Also warn about other cases where a comparison is simplified to a 760constant. For example: <code>abs (x) >= 0</code>. This can only be 761simplified when <samp><span class="option">-fstrict-overflow</span></samp> is in effect, because 762<code>abs (INT_MIN)</code> overflows to <code>INT_MIN</code>, which is less than 763zero. <samp><span class="option">-Wstrict-overflow</span></samp> (with no level) is the same as 764<samp><span class="option">-Wstrict-overflow=2</span></samp>. 765 766 <br><dt><code>-Wstrict-overflow=3</code><dd>Also warn about other cases where a comparison is simplified. For 767example: <code>x + 1 > 1</code> is simplified to <code>x > 0</code>. 768 769 <br><dt><code>-Wstrict-overflow=4</code><dd>Also warn about other simplifications not covered by the above cases. 770For example: <code>(x * 10) / 5</code> is simplified to <code>x * 2</code>. 771 772 <br><dt><code>-Wstrict-overflow=5</code><dd>Also warn about cases where the compiler reduces the magnitude of a 773constant involved in a comparison. For example: <code>x + 2 > y</code> is 774simplified to <code>x + 1 >= y</code>. This is reported only at the 775highest warning level because this simplification applies to many 776comparisons, so this warning level gives a very large number of 777false positives. 778</dl> 779 780 <br><dt><code>-Wsuggest-attribute=</code><span class="roman">[</span><code>pure</code><span class="roman">|</span><code>const</code><span class="roman">|</span><code>noreturn</code><span class="roman">|</span><code>format</code><span class="roman">]</span><dd><a name="index-Wsuggest_002dattribute_003d-361"></a><a name="index-Wno_002dsuggest_002dattribute_003d-362"></a>Warn for cases where adding an attribute may be beneficial. The 781attributes currently supported are listed below. 782 783 <dl> 784<dt><code>-Wsuggest-attribute=pure</code><dt><code>-Wsuggest-attribute=const</code><dt><code>-Wsuggest-attribute=noreturn</code><dd><a name="index-Wsuggest_002dattribute_003dpure-363"></a><a name="index-Wno_002dsuggest_002dattribute_003dpure-364"></a><a name="index-Wsuggest_002dattribute_003dconst-365"></a><a name="index-Wno_002dsuggest_002dattribute_003dconst-366"></a><a name="index-Wsuggest_002dattribute_003dnoreturn-367"></a><a name="index-Wno_002dsuggest_002dattribute_003dnoreturn-368"></a> 785Warn about functions that might be candidates for attributes 786<code>pure</code>, <code>const</code> or <code>noreturn</code>. The compiler only warns for 787functions visible in other compilation units or (in the case of <code>pure</code> and 788<code>const</code>) if it cannot prove that the function returns normally. A function 789returns normally if it doesn't contain an infinite loop or return abnormally 790by throwing, calling <code>abort()</code> or trapping. This analysis requires option 791<samp><span class="option">-fipa-pure-const</span></samp>, which is enabled by default at <samp><span class="option">-O</span></samp> and 792higher. Higher optimization levels improve the accuracy of the analysis. 793 794 <br><dt><code>-Wsuggest-attribute=format</code><dt><code>-Wmissing-format-attribute</code><dd><a name="index-Wsuggest_002dattribute_003dformat-369"></a><a name="index-Wmissing_002dformat_002dattribute-370"></a><a name="index-Wno_002dsuggest_002dattribute_003dformat-371"></a><a name="index-Wno_002dmissing_002dformat_002dattribute-372"></a><a name="index-Wformat-373"></a><a name="index-Wno_002dformat-374"></a> 795Warn about function pointers that might be candidates for <code>format</code> 796attributes. Note these are only possible candidates, not absolute ones. 797GCC guesses that function pointers with <code>format</code> attributes that 798are used in assignment, initialization, parameter passing or return 799statements should have a corresponding <code>format</code> attribute in the 800resulting type. I.e. the left-hand side of the assignment or 801initialization, the type of the parameter variable, or the return type 802of the containing function respectively should also have a <code>format</code> 803attribute to avoid the warning. 804 805 <p>GCC also warns about function definitions that might be 806candidates for <code>format</code> attributes. Again, these are only 807possible candidates. GCC guesses that <code>format</code> attributes 808might be appropriate for any function that calls a function like 809<code>vprintf</code> or <code>vscanf</code>, but this might not always be the 810case, and some functions for which <code>format</code> attributes are 811appropriate may not be detected. 812</dl> 813 814 <br><dt><code>-Warray-bounds</code><dd><a name="index-Wno_002darray_002dbounds-375"></a><a name="index-Warray_002dbounds-376"></a>This option is only active when <samp><span class="option">-ftree-vrp</span></samp> is active 815(default for <samp><span class="option">-O2</span></samp> and above). It warns about subscripts to arrays 816that are always out of bounds. This warning is enabled by <samp><span class="option">-Wall</span></samp>. 817 818 <br><dt><code>-Wno-div-by-zero</code><dd><a name="index-Wno_002ddiv_002dby_002dzero-377"></a><a name="index-Wdiv_002dby_002dzero-378"></a>Do not warn about compile-time integer division by zero. Floating-point 819division by zero is not warned about, as it can be a legitimate way of 820obtaining infinities and NaNs. 821 822 <br><dt><code>-Wsystem-headers</code><dd><a name="index-Wsystem_002dheaders-379"></a><a name="index-Wno_002dsystem_002dheaders-380"></a><a name="index-warnings-from-system-headers-381"></a><a name="index-system-headers_002c-warnings-from-382"></a>Print warning messages for constructs found in system header files. 823Warnings from system headers are normally suppressed, on the assumption 824that they usually do not indicate real problems and would only make the 825compiler output harder to read. Using this command-line option tells 826GCC to emit warnings from system headers as if they occurred in user 827code. However, note that using <samp><span class="option">-Wall</span></samp> in conjunction with this 828option does <em>not</em> warn about unknown pragmas in system 829headers—for that, <samp><span class="option">-Wunknown-pragmas</span></samp> must also be used. 830 831 <br><dt><code>-Wtrampolines</code><dd><a name="index-Wtrampolines-383"></a><a name="index-Wno_002dtrampolines-384"></a> Warn about trampolines generated for pointers to nested functions. 832 833 <p>A trampoline is a small piece of data or code that is created at run 834 time on the stack when the address of a nested function is taken, and 835 is used to call the nested function indirectly. For some targets, it 836 is made up of data only and thus requires no special treatment. But, 837 for most targets, it is made up of code and thus requires the stack 838 to be made executable in order for the program to work properly. 839 840 <br><dt><code>-Wno-poison-system-directories</code><dd><a name="index-Wno_002dpoison_002dsystem_002ddirectories-385"></a>Do not warn for <samp><span class="option">-I</span></samp> or <samp><span class="option">-L</span></samp> options using system 841directories such as <samp><span class="file">/usr/include</span></samp> when cross compiling. This 842option is intended for use in chroot environments when such 843directories contain the correct headers and libraries for the target 844system rather than the host. 845 846 <br><dt><code>-Wfloat-equal</code><dd><a name="index-Wfloat_002dequal-386"></a><a name="index-Wno_002dfloat_002dequal-387"></a>Warn if floating-point values are used in equality comparisons. 847 848 <p>The idea behind this is that sometimes it is convenient (for the 849programmer) to consider floating-point values as approximations to 850infinitely precise real numbers. If you are doing this, then you need 851to compute (by analyzing the code, or in some other way) the maximum or 852likely maximum error that the computation introduces, and allow for it 853when performing comparisons (and when producing output, but that's a 854different problem). In particular, instead of testing for equality, you 855should check to see whether the two values have ranges that overlap; and 856this is done with the relational operators, so equality comparisons are 857probably mistaken. 858 859 <br><dt><code>-Wtraditional </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wtraditional-388"></a><a name="index-Wno_002dtraditional-389"></a>Warn about certain constructs that behave differently in traditional and 860ISO C. Also warn about ISO C constructs that have no traditional C 861equivalent, and/or problematic constructs that should be avoided. 862 863 <ul> 864<li>Macro parameters that appear within string literals in the macro body. 865In traditional C macro replacement takes place within string literals, 866but in ISO C it does not. 867 868 <li>In traditional C, some preprocessor directives did not exist. 869Traditional preprocessors only considered a line to be a directive 870if the ‘<samp><span class="samp">#</span></samp>’ appeared in column 1 on the line. Therefore 871<samp><span class="option">-Wtraditional</span></samp> warns about directives that traditional C 872understands but ignores because the ‘<samp><span class="samp">#</span></samp>’ does not appear as the 873first character on the line. It also suggests you hide directives like 874‘<samp><span class="samp">#pragma</span></samp>’ not understood by traditional C by indenting them. Some 875traditional implementations do not recognize ‘<samp><span class="samp">#elif</span></samp>’, so this option 876suggests avoiding it altogether. 877 878 <li>A function-like macro that appears without arguments. 879 880 <li>The unary plus operator. 881 882 <li>The ‘<samp><span class="samp">U</span></samp>’ integer constant suffix, or the ‘<samp><span class="samp">F</span></samp>’ or ‘<samp><span class="samp">L</span></samp>’ floating-point 883constant suffixes. (Traditional C does support the ‘<samp><span class="samp">L</span></samp>’ suffix on integer 884constants.) Note, these suffixes appear in macros defined in the system 885headers of most modern systems, e.g. the ‘<samp><span class="samp">_MIN</span></samp>’/‘<samp><span class="samp">_MAX</span></samp>’ macros in <code><limits.h></code>. 886Use of these macros in user code might normally lead to spurious 887warnings, however GCC's integrated preprocessor has enough context to 888avoid warning in these cases. 889 890 <li>A function declared external in one block and then used after the end of 891the block. 892 893 <li>A <code>switch</code> statement has an operand of type <code>long</code>. 894 895 <li>A non-<code>static</code> function declaration follows a <code>static</code> one. 896This construct is not accepted by some traditional C compilers. 897 898 <li>The ISO type of an integer constant has a different width or 899signedness from its traditional type. This warning is only issued if 900the base of the constant is ten. I.e. hexadecimal or octal values, which 901typically represent bit patterns, are not warned about. 902 903 <li>Usage of ISO string concatenation is detected. 904 905 <li>Initialization of automatic aggregates. 906 907 <li>Identifier conflicts with labels. Traditional C lacks a separate 908namespace for labels. 909 910 <li>Initialization of unions. If the initializer is zero, the warning is 911omitted. This is done under the assumption that the zero initializer in 912user code appears conditioned on e.g. <code>__STDC__</code> to avoid missing 913initializer warnings and relies on default initialization to zero in the 914traditional C case. 915 916 <li>Conversions by prototypes between fixed/floating-point values and vice 917versa. The absence of these prototypes when compiling with traditional 918C causes serious problems. This is a subset of the possible 919conversion warnings; for the full set use <samp><span class="option">-Wtraditional-conversion</span></samp>. 920 921 <li>Use of ISO C style function definitions. This warning intentionally is 922<em>not</em> issued for prototype declarations or variadic functions 923because these ISO C features appear in your code when using 924libiberty's traditional C compatibility macros, <code>PARAMS</code> and 925<code>VPARAMS</code>. This warning is also bypassed for nested functions 926because that feature is already a GCC extension and thus not relevant to 927traditional C compatibility. 928</ul> 929 930 <br><dt><code>-Wtraditional-conversion </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wtraditional_002dconversion-390"></a><a name="index-Wno_002dtraditional_002dconversion-391"></a>Warn if a prototype causes a type conversion that is different from what 931would happen to the same argument in the absence of a prototype. This 932includes conversions of fixed point to floating and vice versa, and 933conversions changing the width or signedness of a fixed-point argument 934except when the same as the default promotion. 935 936 <br><dt><code>-Wdeclaration-after-statement </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wdeclaration_002dafter_002dstatement-392"></a><a name="index-Wno_002ddeclaration_002dafter_002dstatement-393"></a>Warn when a declaration is found after a statement in a block. This 937construct, known from C++, was introduced with ISO C99 and is by default 938allowed in GCC. It is not supported by ISO C90 and was not supported by 939GCC versions before GCC 3.0. See <a href="Mixed-Declarations.html#Mixed-Declarations">Mixed Declarations</a>. 940 941 <br><dt><code>-Wundef</code><dd><a name="index-Wundef-394"></a><a name="index-Wno_002dundef-395"></a>Warn if an undefined identifier is evaluated in an ‘<samp><span class="samp">#if</span></samp>’ directive. 942 943 <br><dt><code>-Wno-endif-labels</code><dd><a name="index-Wno_002dendif_002dlabels-396"></a><a name="index-Wendif_002dlabels-397"></a>Do not warn whenever an ‘<samp><span class="samp">#else</span></samp>’ or an ‘<samp><span class="samp">#endif</span></samp>’ are followed by text. 944 945 <br><dt><code>-Wshadow</code><dd><a name="index-Wshadow-398"></a><a name="index-Wno_002dshadow-399"></a>Warn whenever a local variable or type declaration shadows another variable, 946parameter, type, or class member (in C++), or whenever a built-in function 947is shadowed. Note that in C++, the compiler warns if a local variable 948shadows an explicit typedef, but not if it shadows a struct/class/enum. 949 950 <br><dt><code>-Wlarger-than=</code><var>len</var><dd><a name="index-Wlarger_002dthan_003d_0040var_007blen_007d-400"></a><a name="index-Wlarger_002dthan_002d_0040var_007blen_007d-401"></a>Warn whenever an object of larger than <var>len</var> bytes is defined. 951 952 <br><dt><code>-Wframe-larger-than=</code><var>len</var><dd><a name="index-Wframe_002dlarger_002dthan-402"></a>Warn if the size of a function frame is larger than <var>len</var> bytes. 953The computation done to determine the stack frame size is approximate 954and not conservative. 955The actual requirements may be somewhat greater than <var>len</var> 956even if you do not get a warning. In addition, any space allocated 957via <code>alloca</code>, variable-length arrays, or related constructs 958is not included by the compiler when determining 959whether or not to issue a warning. 960 961 <br><dt><code>-Wno-free-nonheap-object</code><dd><a name="index-Wno_002dfree_002dnonheap_002dobject-403"></a><a name="index-Wfree_002dnonheap_002dobject-404"></a>Do not warn when attempting to free an object that was not allocated 962on the heap. 963 964 <br><dt><code>-Wstack-usage=</code><var>len</var><dd><a name="index-Wstack_002dusage-405"></a>Warn if the stack usage of a function might be larger than <var>len</var> bytes. 965The computation done to determine the stack usage is conservative. 966Any space allocated via <code>alloca</code>, variable-length arrays, or related 967constructs is included by the compiler when determining whether or not to 968issue a warning. 969 970 <p>The message is in keeping with the output of <samp><span class="option">-fstack-usage</span></samp>. 971 972 <ul> 973<li>If the stack usage is fully static but exceeds the specified amount, it's: 974 975 <pre class="smallexample"> warning: stack usage is 1120 bytes 976</pre> 977 <li>If the stack usage is (partly) dynamic but bounded, it's: 978 979 <pre class="smallexample"> warning: stack usage might be 1648 bytes 980</pre> 981 <li>If the stack usage is (partly) dynamic and not bounded, it's: 982 983 <pre class="smallexample"> warning: stack usage might be unbounded 984</pre> 985 </ul> 986 987 <br><dt><code>-Wunsafe-loop-optimizations</code><dd><a name="index-Wunsafe_002dloop_002doptimizations-406"></a><a name="index-Wno_002dunsafe_002dloop_002doptimizations-407"></a>Warn if the loop cannot be optimized because the compiler cannot 988assume anything on the bounds of the loop indices. With 989<samp><span class="option">-funsafe-loop-optimizations</span></samp> warn if the compiler makes 990such assumptions. 991 992 <br><dt><code>-Wno-pedantic-ms-format </code><span class="roman">(MinGW targets only)</span><dd><a name="index-Wno_002dpedantic_002dms_002dformat-408"></a><a name="index-Wpedantic_002dms_002dformat-409"></a>When used in combination with <samp><span class="option">-Wformat</span></samp> 993and <samp><span class="option">-pedantic</span></samp> without GNU extensions, this option 994disables the warnings about non-ISO <code>printf</code> / <code>scanf</code> format 995width specifiers <code>I32</code>, <code>I64</code>, and <code>I</code> used on Windows targets, 996which depend on the MS runtime. 997 998 <br><dt><code>-Wpointer-arith</code><dd><a name="index-Wpointer_002darith-410"></a><a name="index-Wno_002dpointer_002darith-411"></a>Warn about anything that depends on the “size of” a function type or 999of <code>void</code>. GNU C assigns these types a size of 1, for 1000convenience in calculations with <code>void *</code> pointers and pointers 1001to functions. In C++, warn also when an arithmetic operation involves 1002<code>NULL</code>. This warning is also enabled by <samp><span class="option">-Wpedantic</span></samp>. 1003 1004 <br><dt><code>-Wtype-limits</code><dd><a name="index-Wtype_002dlimits-412"></a><a name="index-Wno_002dtype_002dlimits-413"></a>Warn if a comparison is always true or always false due to the limited 1005range of the data type, but do not warn for constant expressions. For 1006example, warn if an unsigned variable is compared against zero with 1007‘<samp><span class="samp"><</span></samp>’ or ‘<samp><span class="samp">>=</span></samp>’. This warning is also enabled by 1008<samp><span class="option">-Wextra</span></samp>. 1009 1010 <br><dt><code>-Wbad-function-cast </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wbad_002dfunction_002dcast-414"></a><a name="index-Wno_002dbad_002dfunction_002dcast-415"></a>Warn whenever a function call is cast to a non-matching type. 1011For example, warn if <code>int malloc()</code> is cast to <code>anything *</code>. 1012 1013 <br><dt><code>-Wc++-compat </code><span class="roman">(C and Objective-C only)</span><dd>Warn about ISO C constructs that are outside of the common subset of 1014ISO C and ISO C++, e.g. request for implicit conversion from 1015<code>void *</code> to a pointer to non-<code>void</code> type. 1016 1017 <br><dt><code>-Wc++11-compat </code><span class="roman">(C++ and Objective-C++ only)</span><dd>Warn about C++ constructs whose meaning differs between ISO C++ 1998 1018and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are keywords 1019in ISO C++ 2011. This warning turns on <samp><span class="option">-Wnarrowing</span></samp> and is 1020enabled by <samp><span class="option">-Wall</span></samp>. 1021 1022 <br><dt><code>-Wcast-qual</code><dd><a name="index-Wcast_002dqual-416"></a><a name="index-Wno_002dcast_002dqual-417"></a>Warn whenever a pointer is cast so as to remove a type qualifier from 1023the target type. For example, warn if a <code>const char *</code> is cast 1024to an ordinary <code>char *</code>. 1025 1026 <p>Also warn when making a cast that introduces a type qualifier in an 1027unsafe way. For example, casting <code>char **</code> to <code>const char **</code> 1028is unsafe, as in this example: 1029 1030 <pre class="smallexample"> /* p is char ** value. */ 1031 const char **q = (const char **) p; 1032 /* Assignment of readonly string to const char * is OK. */ 1033 *q = "string"; 1034 /* Now char** pointer points to read-only memory. */ 1035 **p = 'b'; 1036</pre> 1037 <br><dt><code>-Wcast-align</code><dd><a name="index-Wcast_002dalign-418"></a><a name="index-Wno_002dcast_002dalign-419"></a>Warn whenever a pointer is cast such that the required alignment of the 1038target is increased. For example, warn if a <code>char *</code> is cast to 1039an <code>int *</code> on machines where integers can only be accessed at 1040two- or four-byte boundaries. 1041 1042 <br><dt><code>-Wwrite-strings</code><dd><a name="index-Wwrite_002dstrings-420"></a><a name="index-Wno_002dwrite_002dstrings-421"></a>When compiling C, give string constants the type <code>const 1043char[</code><var>length</var><code>]</code> so that copying the address of one into a 1044non-<code>const</code> <code>char *</code> pointer produces a warning. These 1045warnings help you find at compile time code that can try to write 1046into a string constant, but only if you have been very careful about 1047using <code>const</code> in declarations and prototypes. Otherwise, it is 1048just a nuisance. This is why we did not make <samp><span class="option">-Wall</span></samp> request 1049these warnings. 1050 1051 <p>When compiling C++, warn about the deprecated conversion from string 1052literals to <code>char *</code>. This warning is enabled by default for C++ 1053programs. 1054 1055 <br><dt><code>-Wclobbered</code><dd><a name="index-Wclobbered-422"></a><a name="index-Wno_002dclobbered-423"></a>Warn for variables that might be changed by ‘<samp><span class="samp">longjmp</span></samp>’ or 1056‘<samp><span class="samp">vfork</span></samp>’. This warning is also enabled by <samp><span class="option">-Wextra</span></samp>. 1057 1058 <br><dt><code>-Wconversion</code><dd><a name="index-Wconversion-424"></a><a name="index-Wno_002dconversion-425"></a>Warn for implicit conversions that may alter a value. This includes 1059conversions between real and integer, like <code>abs (x)</code> when 1060<code>x</code> is <code>double</code>; conversions between signed and unsigned, 1061like <code>unsigned ui = -1</code>; and conversions to smaller types, like 1062<code>sqrtf (M_PI)</code>. Do not warn for explicit casts like <code>abs 1063((int) x)</code> and <code>ui = (unsigned) -1</code>, or if the value is not 1064changed by the conversion like in <code>abs (2.0)</code>. Warnings about 1065conversions between signed and unsigned integers can be disabled by 1066using <samp><span class="option">-Wno-sign-conversion</span></samp>. 1067 1068 <p>For C++, also warn for confusing overload resolution for user-defined 1069conversions; and conversions that never use a type conversion 1070operator: conversions to <code>void</code>, the same type, a base class or a 1071reference to them. Warnings about conversions between signed and 1072unsigned integers are disabled by default in C++ unless 1073<samp><span class="option">-Wsign-conversion</span></samp> is explicitly enabled. 1074 1075 <br><dt><code>-Wno-conversion-null </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wconversion_002dnull-426"></a><a name="index-Wno_002dconversion_002dnull-427"></a>Do not warn for conversions between <code>NULL</code> and non-pointer 1076types. <samp><span class="option">-Wconversion-null</span></samp> is enabled by default. 1077 1078 <br><dt><code>-Wzero-as-null-pointer-constant </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wzero_002das_002dnull_002dpointer_002dconstant-428"></a><a name="index-Wno_002dzero_002das_002dnull_002dpointer_002dconstant-429"></a>Warn when a literal '0' is used as null pointer constant. This can 1079be useful to facilitate the conversion to <code>nullptr</code> in C++11. 1080 1081 <br><dt><code>-Wuseless-cast </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wuseless_002dcast-430"></a><a name="index-Wno_002duseless_002dcast-431"></a>Warn when an expression is casted to its own type. 1082 1083 <br><dt><code>-Wempty-body</code><dd><a name="index-Wempty_002dbody-432"></a><a name="index-Wno_002dempty_002dbody-433"></a>Warn if an empty body occurs in an ‘<samp><span class="samp">if</span></samp>’, ‘<samp><span class="samp">else</span></samp>’ or ‘<samp><span class="samp">do 1084while</span></samp>’ statement. This warning is also enabled by <samp><span class="option">-Wextra</span></samp>. 1085 1086 <br><dt><code>-Wenum-compare</code><dd><a name="index-Wenum_002dcompare-434"></a><a name="index-Wno_002denum_002dcompare-435"></a>Warn about a comparison between values of different enumerated types. 1087In C++ enumeral mismatches in conditional expressions are also 1088diagnosed and the warning is enabled by default. In C this warning is 1089enabled by <samp><span class="option">-Wall</span></samp>. 1090 1091 <br><dt><code>-Wjump-misses-init </code><span class="roman">(C, Objective-C only)</span><dd><a name="index-Wjump_002dmisses_002dinit-436"></a><a name="index-Wno_002djump_002dmisses_002dinit-437"></a>Warn if a <code>goto</code> statement or a <code>switch</code> statement jumps 1092forward across the initialization of a variable, or jumps backward to a 1093label after the variable has been initialized. This only warns about 1094variables that are initialized when they are declared. This warning is 1095only supported for C and Objective-C; in C++ this sort of branch is an 1096error in any case. 1097 1098 <p><samp><span class="option">-Wjump-misses-init</span></samp> is included in <samp><span class="option">-Wc++-compat</span></samp>. It 1099can be disabled with the <samp><span class="option">-Wno-jump-misses-init</span></samp> option. 1100 1101 <br><dt><code>-Wsign-compare</code><dd><a name="index-Wsign_002dcompare-438"></a><a name="index-Wno_002dsign_002dcompare-439"></a><a name="index-warning-for-comparison-of-signed-and-unsigned-values-440"></a><a name="index-comparison-of-signed-and-unsigned-values_002c-warning-441"></a><a name="index-signed-and-unsigned-values_002c-comparison-warning-442"></a>Warn when a comparison between signed and unsigned values could produce 1102an incorrect result when the signed value is converted to unsigned. 1103This warning is also enabled by <samp><span class="option">-Wextra</span></samp>; to get the other warnings 1104of <samp><span class="option">-Wextra</span></samp> without this warning, use <samp><span class="option">-Wextra -Wno-sign-compare</span></samp>. 1105 1106 <br><dt><code>-Wsign-conversion</code><dd><a name="index-Wsign_002dconversion-443"></a><a name="index-Wno_002dsign_002dconversion-444"></a>Warn for implicit conversions that may change the sign of an integer 1107value, like assigning a signed integer expression to an unsigned 1108integer variable. An explicit cast silences the warning. In C, this 1109option is enabled also by <samp><span class="option">-Wconversion</span></samp>. 1110 1111 <br><dt><code>-Wsizeof-pointer-memaccess</code><dd><a name="index-Wsizeof_002dpointer_002dmemaccess-445"></a><a name="index-Wno_002dsizeof_002dpointer_002dmemaccess-446"></a>Warn for suspicious length parameters to certain string and memory built-in 1112functions if the argument uses <code>sizeof</code>. This warning warns e.g. 1113about <code>memset (ptr, 0, sizeof (ptr));</code> if <code>ptr</code> is not an array, 1114but a pointer, and suggests a possible fix, or about 1115<code>memcpy (&foo, ptr, sizeof (&foo));</code>. This warning is enabled by 1116<samp><span class="option">-Wall</span></samp>. 1117 1118 <br><dt><code>-Waddress</code><dd><a name="index-Waddress-447"></a><a name="index-Wno_002daddress-448"></a>Warn about suspicious uses of memory addresses. These include using 1119the address of a function in a conditional expression, such as 1120<code>void func(void); if (func)</code>, and comparisons against the memory 1121address of a string literal, such as <code>if (x == "abc")</code>. Such 1122uses typically indicate a programmer error: the address of a function 1123always evaluates to true, so their use in a conditional usually 1124indicate that the programmer forgot the parentheses in a function 1125call; and comparisons against string literals result in unspecified 1126behavior and are not portable in C, so they usually indicate that the 1127programmer intended to use <code>strcmp</code>. This warning is enabled by 1128<samp><span class="option">-Wall</span></samp>. 1129 1130 <br><dt><code>-Wlogical-op</code><dd><a name="index-Wlogical_002dop-449"></a><a name="index-Wno_002dlogical_002dop-450"></a>Warn about suspicious uses of logical operators in expressions. 1131This includes using logical operators in contexts where a 1132bit-wise operator is likely to be expected. 1133 1134 <br><dt><code>-Waggregate-return</code><dd><a name="index-Waggregate_002dreturn-451"></a><a name="index-Wno_002daggregate_002dreturn-452"></a>Warn if any functions that return structures or unions are defined or 1135called. (In languages where you can return an array, this also elicits 1136a warning.) 1137 1138 <br><dt><code>-Wno-aggressive-loop-optimizations</code><dd><a name="index-Wno_002daggressive_002dloop_002doptimizations-453"></a><a name="index-Waggressive_002dloop_002doptimizations-454"></a>Warn if in a loop with constant number of iterations the compiler detects 1139undefined behavior in some statement during one or more of the iterations. 1140 1141 <br><dt><code>-Wno-attributes</code><dd><a name="index-Wno_002dattributes-455"></a><a name="index-Wattributes-456"></a>Do not warn if an unexpected <code>__attribute__</code> is used, such as 1142unrecognized attributes, function attributes applied to variables, 1143etc. This does not stop errors for incorrect use of supported 1144attributes. 1145 1146 <br><dt><code>-Wno-builtin-macro-redefined</code><dd><a name="index-Wno_002dbuiltin_002dmacro_002dredefined-457"></a><a name="index-Wbuiltin_002dmacro_002dredefined-458"></a>Do not warn if certain built-in macros are redefined. This suppresses 1147warnings for redefinition of <code>__TIMESTAMP__</code>, <code>__TIME__</code>, 1148<code>__DATE__</code>, <code>__FILE__</code>, and <code>__BASE_FILE__</code>. 1149 1150 <br><dt><code>-Wstrict-prototypes </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wstrict_002dprototypes-459"></a><a name="index-Wno_002dstrict_002dprototypes-460"></a>Warn if a function is declared or defined without specifying the 1151argument types. (An old-style function definition is permitted without 1152a warning if preceded by a declaration that specifies the argument 1153types.) 1154 1155 <br><dt><code>-Wold-style-declaration </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wold_002dstyle_002ddeclaration-461"></a><a name="index-Wno_002dold_002dstyle_002ddeclaration-462"></a>Warn for obsolescent usages, according to the C Standard, in a 1156declaration. For example, warn if storage-class specifiers like 1157<code>static</code> are not the first things in a declaration. This warning 1158is also enabled by <samp><span class="option">-Wextra</span></samp>. 1159 1160 <br><dt><code>-Wold-style-definition </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wold_002dstyle_002ddefinition-463"></a><a name="index-Wno_002dold_002dstyle_002ddefinition-464"></a>Warn if an old-style function definition is used. A warning is given 1161even if there is a previous prototype. 1162 1163 <br><dt><code>-Wmissing-parameter-type </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wmissing_002dparameter_002dtype-465"></a><a name="index-Wno_002dmissing_002dparameter_002dtype-466"></a>A function parameter is declared without a type specifier in K&R-style 1164functions: 1165 1166 <pre class="smallexample"> void foo(bar) { } 1167</pre> 1168 <p>This warning is also enabled by <samp><span class="option">-Wextra</span></samp>. 1169 1170 <br><dt><code>-Wmissing-prototypes </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wmissing_002dprototypes-467"></a><a name="index-Wno_002dmissing_002dprototypes-468"></a>Warn if a global function is defined without a previous prototype 1171declaration. This warning is issued even if the definition itself 1172provides a prototype. Use this option to detect global functions 1173that do not have a matching prototype declaration in a header file. 1174This option is not valid for C++ because all function declarations 1175provide prototypes and a non-matching declaration will declare an 1176overload rather than conflict with an earlier declaration. 1177Use <samp><span class="option">-Wmissing-declarations</span></samp> to detect missing declarations in C++. 1178 1179 <br><dt><code>-Wmissing-declarations</code><dd><a name="index-Wmissing_002ddeclarations-469"></a><a name="index-Wno_002dmissing_002ddeclarations-470"></a>Warn if a global function is defined without a previous declaration. 1180Do so even if the definition itself provides a prototype. 1181Use this option to detect global functions that are not declared in 1182header files. In C, no warnings are issued for functions with previous 1183non-prototype declarations; use <samp><span class="option">-Wmissing-prototype</span></samp> to detect 1184missing prototypes. In C++, no warnings are issued for function templates, 1185or for inline functions, or for functions in anonymous namespaces. 1186 1187 <br><dt><code>-Wmissing-field-initializers</code><dd><a name="index-Wmissing_002dfield_002dinitializers-471"></a><a name="index-Wno_002dmissing_002dfield_002dinitializers-472"></a><a name="index-W-473"></a><a name="index-Wextra-474"></a><a name="index-Wno_002dextra-475"></a>Warn if a structure's initializer has some fields missing. For 1188example, the following code causes such a warning, because 1189<code>x.h</code> is implicitly zero: 1190 1191 <pre class="smallexample"> struct s { int f, g, h; }; 1192 struct s x = { 3, 4 }; 1193</pre> 1194 <p>This option does not warn about designated initializers, so the following 1195modification does not trigger a warning: 1196 1197 <pre class="smallexample"> struct s { int f, g, h; }; 1198 struct s x = { .f = 3, .g = 4 }; 1199</pre> 1200 <p>This warning is included in <samp><span class="option">-Wextra</span></samp>. To get other <samp><span class="option">-Wextra</span></samp> 1201warnings without this one, use <samp><span class="option">-Wextra -Wno-missing-field-initializers</span></samp>. 1202 1203 <br><dt><code>-Wno-multichar</code><dd><a name="index-Wno_002dmultichar-476"></a><a name="index-Wmultichar-477"></a>Do not warn if a multicharacter constant (‘<samp><span class="samp">'FOOF'</span></samp>’) is used. 1204Usually they indicate a typo in the user's code, as they have 1205implementation-defined values, and should not be used in portable code. 1206 1207 <br><dt><code>-Wnormalized=<none|id|nfc|nfkc></code><dd><a name="index-Wnormalized_003d-478"></a><a name="index-NFC-479"></a><a name="index-NFKC-480"></a><a name="index-character-set_002c-input-normalization-481"></a>In ISO C and ISO C++, two identifiers are different if they are 1208different sequences of characters. However, sometimes when characters 1209outside the basic ASCII character set are used, you can have two 1210different character sequences that look the same. To avoid confusion, 1211the ISO 10646 standard sets out some <dfn>normalization rules</dfn> which 1212when applied ensure that two sequences that look the same are turned into 1213the same sequence. GCC can warn you if you are using identifiers that 1214have not been normalized; this option controls that warning. 1215 1216 <p>There are four levels of warning supported by GCC. The default is 1217<samp><span class="option">-Wnormalized=nfc</span></samp>, which warns about any identifier that is 1218not in the ISO 10646 “C” normalized form, <dfn>NFC</dfn>. NFC is the 1219recommended form for most uses. 1220 1221 <p>Unfortunately, there are some characters allowed in identifiers by 1222ISO C and ISO C++ that, when turned into NFC, are not allowed in 1223identifiers. That is, there's no way to use these symbols in portable 1224ISO C or C++ and have all your identifiers in NFC. 1225<samp><span class="option">-Wnormalized=id</span></samp> suppresses the warning for these characters. 1226It is hoped that future versions of the standards involved will correct 1227this, which is why this option is not the default. 1228 1229 <p>You can switch the warning off for all characters by writing 1230<samp><span class="option">-Wnormalized=none</span></samp>. You should only do this if you 1231are using some other normalization scheme (like “D”), because 1232otherwise you can easily create bugs that are literally impossible to see. 1233 1234 <p>Some characters in ISO 10646 have distinct meanings but look identical 1235in some fonts or display methodologies, especially once formatting has 1236been applied. For instance <code>\u207F</code>, “SUPERSCRIPT LATIN SMALL 1237LETTER N”, displays just like a regular <code>n</code> that has been 1238placed in a superscript. ISO 10646 defines the <dfn>NFKC</dfn> 1239normalization scheme to convert all these into a standard form as 1240well, and GCC warns if your code is not in NFKC if you use 1241<samp><span class="option">-Wnormalized=nfkc</span></samp>. This warning is comparable to warning 1242about every identifier that contains the letter O because it might be 1243confused with the digit 0, and so is not the default, but may be 1244useful as a local coding convention if the programming environment 1245cannot be fixed to display these characters distinctly. 1246 1247 <br><dt><code>-Wno-deprecated</code><dd><a name="index-Wno_002ddeprecated-482"></a><a name="index-Wdeprecated-483"></a>Do not warn about usage of deprecated features. See <a href="Deprecated-Features.html#Deprecated-Features">Deprecated Features</a>. 1248 1249 <br><dt><code>-Wno-deprecated-declarations</code><dd><a name="index-Wno_002ddeprecated_002ddeclarations-484"></a><a name="index-Wdeprecated_002ddeclarations-485"></a>Do not warn about uses of functions (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>), 1250variables (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>), and types (see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>) marked as deprecated by using the <code>deprecated</code> 1251attribute. 1252 1253 <br><dt><code>-Wno-overflow</code><dd><a name="index-Wno_002doverflow-486"></a><a name="index-Woverflow-487"></a>Do not warn about compile-time overflow in constant expressions. 1254 1255 <br><dt><code>-Woverride-init </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Woverride_002dinit-488"></a><a name="index-Wno_002doverride_002dinit-489"></a><a name="index-W-490"></a><a name="index-Wextra-491"></a><a name="index-Wno_002dextra-492"></a>Warn if an initialized field without side effects is overridden when 1256using designated initializers (see <a href="Designated-Inits.html#Designated-Inits">Designated Initializers</a>). 1257 1258 <p>This warning is included in <samp><span class="option">-Wextra</span></samp>. To get other 1259<samp><span class="option">-Wextra</span></samp> warnings without this one, use <samp><span class="option">-Wextra 1260-Wno-override-init</span></samp>. 1261 1262 <br><dt><code>-Wpacked</code><dd><a name="index-Wpacked-493"></a><a name="index-Wno_002dpacked-494"></a>Warn if a structure is given the packed attribute, but the packed 1263attribute has no effect on the layout or size of the structure. 1264Such structures may be mis-aligned for little benefit. For 1265instance, in this code, the variable <code>f.x</code> in <code>struct bar</code> 1266is misaligned even though <code>struct bar</code> does not itself 1267have the packed attribute: 1268 1269 <pre class="smallexample"> struct foo { 1270 int x; 1271 char a, b, c, d; 1272 } __attribute__((packed)); 1273 struct bar { 1274 char z; 1275 struct foo f; 1276 }; 1277</pre> 1278 <br><dt><code>-Wpacked-bitfield-compat</code><dd><a name="index-Wpacked_002dbitfield_002dcompat-495"></a><a name="index-Wno_002dpacked_002dbitfield_002dcompat-496"></a>The 4.1, 4.2 and 4.3 series of GCC ignore the <code>packed</code> attribute 1279on bit-fields of type <code>char</code>. This has been fixed in GCC 4.4 but 1280the change can lead to differences in the structure layout. GCC 1281informs you when the offset of such a field has changed in GCC 4.4. 1282For example there is no longer a 4-bit padding between field <code>a</code> 1283and <code>b</code> in this structure: 1284 1285 <pre class="smallexample"> struct foo 1286 { 1287 char a:4; 1288 char b:8; 1289 } __attribute__ ((packed)); 1290</pre> 1291 <p>This warning is enabled by default. Use 1292<samp><span class="option">-Wno-packed-bitfield-compat</span></samp> to disable this warning. 1293 1294 <br><dt><code>-Wpadded</code><dd><a name="index-Wpadded-497"></a><a name="index-Wno_002dpadded-498"></a>Warn if padding is included in a structure, either to align an element 1295of the structure or to align the whole structure. Sometimes when this 1296happens it is possible to rearrange the fields of the structure to 1297reduce the padding and so make the structure smaller. 1298 1299 <br><dt><code>-Wredundant-decls</code><dd><a name="index-Wredundant_002ddecls-499"></a><a name="index-Wno_002dredundant_002ddecls-500"></a>Warn if anything is declared more than once in the same scope, even in 1300cases where multiple declaration is valid and changes nothing. 1301 1302 <br><dt><code>-Wnested-externs </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wnested_002dexterns-501"></a><a name="index-Wno_002dnested_002dexterns-502"></a>Warn if an <code>extern</code> declaration is encountered within a function. 1303 1304 <br><dt><code>-Wno-inherited-variadic-ctor</code><dd><a name="index-Winherited_002dvariadic_002dctor-503"></a><a name="index-Wno_002dinherited_002dvariadic_002dctor-504"></a>Suppress warnings about use of C++11 inheriting constructors when the 1305base class inherited from has a C variadic constructor; the warning is 1306on by default because the ellipsis is not inherited. 1307 1308 <br><dt><code>-Winline</code><dd><a name="index-Winline-505"></a><a name="index-Wno_002dinline-506"></a>Warn if a function that is declared as inline cannot be inlined. 1309Even with this option, the compiler does not warn about failures to 1310inline functions declared in system headers. 1311 1312 <p>The compiler uses a variety of heuristics to determine whether or not 1313to inline a function. For example, the compiler takes into account 1314the size of the function being inlined and the amount of inlining 1315that has already been done in the current function. Therefore, 1316seemingly insignificant changes in the source program can cause the 1317warnings produced by <samp><span class="option">-Winline</span></samp> to appear or disappear. 1318 1319 <br><dt><code>-Wno-invalid-offsetof </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wno_002dinvalid_002doffsetof-507"></a><a name="index-Winvalid_002doffsetof-508"></a>Suppress warnings from applying the ‘<samp><span class="samp">offsetof</span></samp>’ macro to a non-POD 1320type. According to the 1998 ISO C++ standard, applying ‘<samp><span class="samp">offsetof</span></samp>’ 1321to a non-POD type is undefined. In existing C++ implementations, 1322however, ‘<samp><span class="samp">offsetof</span></samp>’ typically gives meaningful results even when 1323applied to certain kinds of non-POD types (such as a simple 1324‘<samp><span class="samp">struct</span></samp>’ that fails to be a POD type only by virtue of having a 1325constructor). This flag is for users who are aware that they are 1326writing nonportable code and who have deliberately chosen to ignore the 1327warning about it. 1328 1329 <p>The restrictions on ‘<samp><span class="samp">offsetof</span></samp>’ may be relaxed in a future version 1330of the C++ standard. 1331 1332 <br><dt><code>-Wno-int-to-pointer-cast</code><dd><a name="index-Wno_002dint_002dto_002dpointer_002dcast-509"></a><a name="index-Wint_002dto_002dpointer_002dcast-510"></a>Suppress warnings from casts to pointer type of an integer of a 1333different size. In C++, casting to a pointer type of smaller size is 1334an error. <samp><span class="option">Wint-to-pointer-cast</span></samp> is enabled by default. 1335 1336 <br><dt><code>-Wno-pointer-to-int-cast </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wno_002dpointer_002dto_002dint_002dcast-511"></a><a name="index-Wpointer_002dto_002dint_002dcast-512"></a>Suppress warnings from casts from a pointer to an integer type of a 1337different size. 1338 1339 <br><dt><code>-Winvalid-pch</code><dd><a name="index-Winvalid_002dpch-513"></a><a name="index-Wno_002dinvalid_002dpch-514"></a>Warn if a precompiled header (see <a href="Precompiled-Headers.html#Precompiled-Headers">Precompiled Headers</a>) is found in 1340the search path but can't be used. 1341 1342 <br><dt><code>-Wlong-long</code><dd><a name="index-Wlong_002dlong-515"></a><a name="index-Wno_002dlong_002dlong-516"></a>Warn if ‘<samp><span class="samp">long long</span></samp>’ type is used. This is enabled by either 1343<samp><span class="option">-Wpedantic</span></samp> or <samp><span class="option">-Wtraditional</span></samp> in ISO C90 and C++98 1344modes. To inhibit the warning messages, use <samp><span class="option">-Wno-long-long</span></samp>. 1345 1346 <br><dt><code>-Wvariadic-macros</code><dd><a name="index-Wvariadic_002dmacros-517"></a><a name="index-Wno_002dvariadic_002dmacros-518"></a>Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU 1347alternate syntax when in pedantic ISO C99 mode. This is default. 1348To inhibit the warning messages, use <samp><span class="option">-Wno-variadic-macros</span></samp>. 1349 1350 <br><dt><code>-Wvarargs</code><dd><a name="index-Wvarargs-519"></a><a name="index-Wno_002dvarargs-520"></a>Warn upon questionable usage of the macros used to handle variable 1351arguments like ‘<samp><span class="samp">va_start</span></samp>’. This is default. To inhibit the 1352warning messages, use <samp><span class="option">-Wno-varargs</span></samp>. 1353 1354 <br><dt><code>-Wvector-operation-performance</code><dd><a name="index-Wvector_002doperation_002dperformance-521"></a><a name="index-Wno_002dvector_002doperation_002dperformance-522"></a>Warn if vector operation is not implemented via SIMD capabilities of the 1355architecture. Mainly useful for the performance tuning. 1356Vector operation can be implemented <code>piecewise</code>, which means that the 1357scalar operation is performed on every vector element; 1358<code>in parallel</code>, which means that the vector operation is implemented 1359using scalars of wider type, which normally is more performance efficient; 1360and <code>as a single scalar</code>, which means that vector fits into a 1361scalar type. 1362 1363 <br><dt><code>-Wno-virtual-move-assign</code><dd><a name="index-Wvirtual_002dmove_002dassign-523"></a><a name="index-Wno_002dvirtual_002dmove_002dassign-524"></a>Suppress warnings about inheriting from a virtual base with a 1364non-trivial C++11 move assignment operator. This is dangerous because 1365if the virtual base is reachable along more than one path, it will be 1366moved multiple times, which can mean both objects end up in the 1367moved-from state. If the move assignment operator is written to avoid 1368moving from a moved-from object, this warning can be disabled. 1369 1370 <br><dt><code>-Wvla</code><dd><a name="index-Wvla-525"></a><a name="index-Wno_002dvla-526"></a>Warn if variable length array is used in the code. 1371<samp><span class="option">-Wno-vla</span></samp> prevents the <samp><span class="option">-Wpedantic</span></samp> warning of 1372the variable length array. 1373 1374 <br><dt><code>-Wvolatile-register-var</code><dd><a name="index-Wvolatile_002dregister_002dvar-527"></a><a name="index-Wno_002dvolatile_002dregister_002dvar-528"></a>Warn if a register variable is declared volatile. The volatile 1375modifier does not inhibit all optimizations that may eliminate reads 1376and/or writes to register variables. This warning is enabled by 1377<samp><span class="option">-Wall</span></samp>. 1378 1379 <br><dt><code>-Wdisabled-optimization</code><dd><a name="index-Wdisabled_002doptimization-529"></a><a name="index-Wno_002ddisabled_002doptimization-530"></a>Warn if a requested optimization pass is disabled. This warning does 1380not generally indicate that there is anything wrong with your code; it 1381merely indicates that GCC's optimizers are unable to handle the code 1382effectively. Often, the problem is that your code is too big or too 1383complex; GCC refuses to optimize programs when the optimization 1384itself is likely to take inordinate amounts of time. 1385 1386 <br><dt><code>-Wpointer-sign </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wpointer_002dsign-531"></a><a name="index-Wno_002dpointer_002dsign-532"></a>Warn for pointer argument passing or assignment with different signedness. 1387This option is only supported for C and Objective-C. It is implied by 1388<samp><span class="option">-Wall</span></samp> and by <samp><span class="option">-Wpedantic</span></samp>, which can be disabled with 1389<samp><span class="option">-Wno-pointer-sign</span></samp>. 1390 1391 <br><dt><code>-Wstack-protector</code><dd><a name="index-Wstack_002dprotector-533"></a><a name="index-Wno_002dstack_002dprotector-534"></a>This option is only active when <samp><span class="option">-fstack-protector</span></samp> is active. It 1392warns about functions that are not protected against stack smashing. 1393 1394 <br><dt><code>-Wno-mudflap</code><dd><a name="index-Wno_002dmudflap-535"></a>Suppress warnings about constructs that cannot be instrumented by 1395<samp><span class="option">-fmudflap</span></samp>. 1396 1397 <br><dt><code>-Woverlength-strings</code><dd><a name="index-Woverlength_002dstrings-536"></a><a name="index-Wno_002doverlength_002dstrings-537"></a>Warn about string constants that are longer than the “minimum 1398maximum” length specified in the C standard. Modern compilers 1399generally allow string constants that are much longer than the 1400standard's minimum limit, but very portable programs should avoid 1401using longer strings. 1402 1403 <p>The limit applies <em>after</em> string constant concatenation, and does 1404not count the trailing NUL. In C90, the limit was 509 characters; in 1405C99, it was raised to 4095. C++98 does not specify a normative 1406minimum maximum, so we do not diagnose overlength strings in C++. 1407 1408 <p>This option is implied by <samp><span class="option">-Wpedantic</span></samp>, and can be disabled with 1409<samp><span class="option">-Wno-overlength-strings</span></samp>. 1410 1411 <br><dt><code>-Wunsuffixed-float-constants </code><span class="roman">(C and Objective-C only)</span><dd><a name="index-Wunsuffixed_002dfloat_002dconstants-538"></a> 1412Issue a warning for any floating constant that does not have 1413a suffix. When used together with <samp><span class="option">-Wsystem-headers</span></samp> it 1414warns about such constants in system header files. This can be useful 1415when preparing code to use with the <code>FLOAT_CONST_DECIMAL64</code> pragma 1416from the decimal floating-point extension to C99. 1417</dl> 1418 1419 </body></html> 1420 1421