Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

3902 lines
171KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Warning Options (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Warning Options (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Warning Options (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Invoking-GCC.html#Invoking-GCC" rel="up" title="Invoking GCC">
  30. <link href="Static-Analyzer-Options.html#Static-Analyzer-Options" rel="next" title="Static Analyzer Options">
  31. <link href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" rel="prev" title="Diagnostic Message Formatting Options">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Warning-Options"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Static-Analyzer-Options.html#Static-Analyzer-Options" accesskey="n" rel="next">Static Analyzer Options</a>, Previous: <a href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" accesskey="p" rel="prev">Diagnostic Message Formatting Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Options-to-Request-or-Suppress-Warnings"></a>
  68. <h3 class="section">3.8 Options to Request or Suppress Warnings</h3>
  69. <a name="index-options-to-control-warnings"></a>
  70. <a name="index-warning-messages"></a>
  71. <a name="index-messages_002c-warning"></a>
  72. <a name="index-suppressing-warnings"></a>
  73. <p>Warnings are diagnostic messages that report constructions that
  74. are not inherently erroneous but that are risky or suggest there
  75. may have been an error.
  76. </p>
  77. <p>The following language-independent options do not enable specific
  78. warnings but control the kinds of diagnostics produced by GCC.
  79. </p>
  80. <dl compact="compact">
  81. <dd><a name="index-syntax-checking"></a>
  82. </dd>
  83. <dt><code>-fsyntax-only</code></dt>
  84. <dd><a name="index-fsyntax_002donly"></a>
  85. <p>Check the code for syntax errors, but don&rsquo;t do anything beyond that.
  86. </p>
  87. </dd>
  88. <dt><code>-fmax-errors=<var>n</var></code></dt>
  89. <dd><a name="index-fmax_002derrors"></a>
  90. <p>Limits the maximum number of error messages to <var>n</var>, at which point
  91. GCC bails out rather than attempting to continue processing the source
  92. code. If <var>n</var> is 0 (the default), there is no limit on the number
  93. of error messages produced. If <samp>-Wfatal-errors</samp> is also
  94. specified, then <samp>-Wfatal-errors</samp> takes precedence over this
  95. option.
  96. </p>
  97. </dd>
  98. <dt><code>-w</code></dt>
  99. <dd><a name="index-w"></a>
  100. <p>Inhibit all warning messages.
  101. </p>
  102. </dd>
  103. <dt><code>-Werror</code></dt>
  104. <dd><a name="index-Werror"></a>
  105. <a name="index-Wno_002derror"></a>
  106. <p>Make all warnings into errors.
  107. </p>
  108. </dd>
  109. <dt><code>-Werror=</code></dt>
  110. <dd><a name="index-Werror_003d"></a>
  111. <a name="index-Wno_002derror_003d"></a>
  112. <p>Make the specified warning into an error. The specifier for a warning
  113. is appended; for example <samp>-Werror=switch</samp> turns the warnings
  114. controlled by <samp>-Wswitch</samp> into errors. This switch takes a
  115. negative form, to be used to negate <samp>-Werror</samp> for specific
  116. warnings; for example <samp>-Wno-error=switch</samp> makes
  117. <samp>-Wswitch</samp> warnings not be errors, even when <samp>-Werror</samp>
  118. is in effect.
  119. </p>
  120. <p>The warning message for each controllable warning includes the
  121. option that controls the warning. That option can then be used with
  122. <samp>-Werror=</samp> and <samp>-Wno-error=</samp> as described above.
  123. (Printing of the option in the warning message can be disabled using the
  124. <samp>-fno-diagnostics-show-option</samp> flag.)
  125. </p>
  126. <p>Note that specifying <samp>-Werror=</samp><var>foo</var> automatically implies
  127. <samp>-W</samp><var>foo</var>. However, <samp>-Wno-error=</samp><var>foo</var> does not
  128. imply anything.
  129. </p>
  130. </dd>
  131. <dt><code>-Wfatal-errors</code></dt>
  132. <dd><a name="index-Wfatal_002derrors"></a>
  133. <a name="index-Wno_002dfatal_002derrors"></a>
  134. <p>This option causes the compiler to abort compilation on the first error
  135. occurred rather than trying to keep going and printing further error
  136. messages.
  137. </p>
  138. </dd>
  139. </dl>
  140. <p>You can request many specific warnings with options beginning with
  141. &lsquo;<samp>-W</samp>&rsquo;, for example <samp>-Wimplicit</samp> to request warnings on
  142. implicit declarations. Each of these specific warning options also
  143. has a negative form beginning &lsquo;<samp>-Wno-</samp>&rsquo; to turn off warnings; for
  144. example, <samp>-Wno-implicit</samp>. This manual lists only one of the
  145. two forms, whichever is not the default. For further
  146. language-specific options also refer to <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options">C++ Dialect Options</a> and
  147. <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>.
  148. Additional warnings can be produced by enabling the static analyzer;
  149. See <a href="Static-Analyzer-Options.html#Static-Analyzer-Options">Static Analyzer Options</a>.
  150. </p>
  151. <p>Some options, such as <samp>-Wall</samp> and <samp>-Wextra</samp>, turn on other
  152. options, such as <samp>-Wunused</samp>, which may turn on further options,
  153. such as <samp>-Wunused-value</samp>. The combined effect of positive and
  154. negative forms is that more specific options have priority over less
  155. specific ones, independently of their position in the command-line. For
  156. options of the same specificity, the last one takes effect. Options
  157. enabled or disabled via pragmas (see <a href="Diagnostic-Pragmas.html#Diagnostic-Pragmas">Diagnostic Pragmas</a>) take effect
  158. as if they appeared at the end of the command-line.
  159. </p>
  160. <p>When an unrecognized warning option is requested (e.g.,
  161. <samp>-Wunknown-warning</samp>), GCC emits a diagnostic stating
  162. that the option is not recognized. However, if the <samp>-Wno-</samp> form
  163. is used, the behavior is slightly different: no diagnostic is
  164. produced for <samp>-Wno-unknown-warning</samp> unless other diagnostics
  165. are being produced. This allows the use of new <samp>-Wno-</samp> options
  166. with old compilers, but if something goes wrong, the compiler
  167. warns that an unrecognized option is present.
  168. </p>
  169. <p>The effectiveness of some warnings depends on optimizations also being
  170. enabled. For example <samp>-Wsuggest-final-types</samp> is more effective
  171. with link-time optimization and <samp>-Wmaybe-uninitialized</samp> does not
  172. warn at all unless optimization is enabled.
  173. </p>
  174. <dl compact="compact">
  175. <dt><code>-Wpedantic</code></dt>
  176. <dt><code>-pedantic</code></dt>
  177. <dd><a name="index-pedantic-1"></a>
  178. <a name="index-Wpedantic"></a>
  179. <a name="index-Wno_002dpedantic"></a>
  180. <p>Issue all the warnings demanded by strict ISO C and ISO C++;
  181. reject all programs that use forbidden extensions, and some other
  182. programs that do not follow ISO C and ISO C++. For ISO C, follows the
  183. version of the ISO C standard specified by any <samp>-std</samp> option used.
  184. </p>
  185. <p>Valid ISO C and ISO C++ programs should compile properly with or without
  186. this option (though a rare few require <samp>-ansi</samp> or a
  187. <samp>-std</samp> option specifying the required version of ISO C). However,
  188. without this option, certain GNU extensions and traditional C and C++
  189. features are supported as well. With this option, they are rejected.
  190. </p>
  191. <p><samp>-Wpedantic</samp> does not cause warning messages for use of the
  192. alternate keywords whose names begin and end with &lsquo;<samp>__</samp>&rsquo;. This alternate
  193. format can also be used to disable warnings for non-ISO &lsquo;<samp>__intN</samp>&rsquo; types,
  194. i.e. &lsquo;<samp>__intN__</samp>&rsquo;.
  195. Pedantic warnings are also disabled in the expression that follows
  196. <code>__extension__</code>. However, only system header files should use
  197. these escape routes; application programs should avoid them.
  198. See <a href="Alternate-Keywords.html#Alternate-Keywords">Alternate Keywords</a>.
  199. </p>
  200. <p>Some users try to use <samp>-Wpedantic</samp> to check programs for strict ISO
  201. C conformance. They soon find that it does not do quite what they want:
  202. it finds some non-ISO practices, but not all&mdash;only those for which
  203. ISO C <em>requires</em> a diagnostic, and some others for which
  204. diagnostics have been added.
  205. </p>
  206. <p>A feature to report any failure to conform to ISO C might be useful in
  207. some instances, but would require considerable additional work and would
  208. be quite different from <samp>-Wpedantic</samp>. We don&rsquo;t have plans to
  209. support such a feature in the near future.
  210. </p>
  211. <p>Where the standard specified with <samp>-std</samp> represents a GNU
  212. extended dialect of C, such as &lsquo;<samp>gnu90</samp>&rsquo; or &lsquo;<samp>gnu99</samp>&rsquo;, there is a
  213. corresponding <em>base standard</em>, the version of ISO C on which the GNU
  214. extended dialect is based. Warnings from <samp>-Wpedantic</samp> are given
  215. where they are required by the base standard. (It does not make sense
  216. for such warnings to be given only for features not in the specified GNU
  217. C dialect, since by definition the GNU dialects of C include all
  218. features the compiler supports with the given option, and there would be
  219. nothing to warn about.)
  220. </p>
  221. </dd>
  222. <dt><code>-pedantic-errors</code></dt>
  223. <dd><a name="index-pedantic_002derrors-1"></a>
  224. <p>Give an error whenever the <em>base standard</em> (see <samp>-Wpedantic</samp>)
  225. requires a diagnostic, in some cases where there is undefined behavior
  226. at compile-time and in some other cases that do not prevent compilation
  227. of programs that are valid according to the standard. This is not
  228. equivalent to <samp>-Werror=pedantic</samp>, since there are errors enabled
  229. by this option and not enabled by the latter and vice versa.
  230. </p>
  231. </dd>
  232. <dt><code>-Wall</code></dt>
  233. <dd><a name="index-Wall"></a>
  234. <a name="index-Wno_002dall"></a>
  235. <p>This enables all the warnings about constructions that some users
  236. consider questionable, and that are easy to avoid (or modify to
  237. prevent the warning), even in conjunction with macros. This also
  238. enables 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>.
  239. </p>
  240. <p><samp>-Wall</samp> turns on the following warning flags:
  241. </p>
  242. <div class="smallexample">
  243. <pre class="smallexample">-Waddress
  244. -Warray-bounds=1 <span class="roman">(only with</span> <samp>-O2</samp><span class="roman">)</span>
  245. -Wbool-compare
  246. -Wbool-operation
  247. -Wc++11-compat -Wc++14-compat
  248. -Wcatch-value <span class="roman">(C++ and Objective-C++ only)</span>
  249. -Wchar-subscripts
  250. -Wcomment
  251. -Wduplicate-decl-specifier <span class="roman">(C and Objective-C only)</span>
  252. -Wenum-compare <span class="roman">(in C/ObjC; this is on by default in C++)</span>
  253. -Wenum-conversion <span class="roman">in C/ObjC;</span>
  254. -Wformat
  255. -Wformat-overflow
  256. -Wformat-truncation
  257. -Wint-in-bool-context
  258. -Wimplicit <span class="roman">(C and Objective-C only)</span>
  259. -Wimplicit-int <span class="roman">(C and Objective-C only)</span>
  260. -Wimplicit-function-declaration <span class="roman">(C and Objective-C only)</span>
  261. -Winit-self <span class="roman">(only for C++)</span>
  262. -Wlogical-not-parentheses
  263. -Wmain <span class="roman">(only for C/ObjC and unless</span> <samp>-ffreestanding</samp><span class="roman">)</span>
  264. -Wmaybe-uninitialized
  265. -Wmemset-elt-size
  266. -Wmemset-transposed-args
  267. -Wmisleading-indentation <span class="roman">(only for C/C++)</span>
  268. -Wmissing-attributes
  269. -Wmissing-braces <span class="roman">(only for C/ObjC)</span>
  270. -Wmultistatement-macros
  271. -Wnarrowing <span class="roman">(only for C++)</span>
  272. -Wnonnull
  273. -Wnonnull-compare
  274. -Wopenmp-simd
  275. -Wparentheses
  276. -Wpessimizing-move <span class="roman">(only for C++)</span>
  277. -Wpointer-sign
  278. -Wreorder
  279. -Wrestrict
  280. -Wreturn-type
  281. -Wsequence-point
  282. -Wsign-compare <span class="roman">(only in C++)</span>
  283. -Wsizeof-pointer-div
  284. -Wsizeof-pointer-memaccess
  285. -Wstrict-aliasing
  286. -Wstrict-overflow=1
  287. -Wswitch
  288. -Wtautological-compare
  289. -Wtrigraphs
  290. -Wuninitialized
  291. -Wunknown-pragmas
  292. -Wunused-function
  293. -Wunused-label
  294. -Wunused-value
  295. -Wunused-variable
  296. -Wvolatile-register-var
  297. -Wzero-length-bounds
  298. </pre></div>
  299. <p>Note that some warning flags are not implied by <samp>-Wall</samp>. Some of
  300. them warn about constructions that users generally do not consider
  301. questionable, but which occasionally you might wish to check for;
  302. others warn about constructions that are necessary or hard to avoid in
  303. some cases, and there is no simple way to modify the code to suppress
  304. the warning. Some of them are enabled by <samp>-Wextra</samp> but many of
  305. them must be enabled individually.
  306. </p>
  307. </dd>
  308. <dt><code>-Wextra</code></dt>
  309. <dd><a name="index-W"></a>
  310. <a name="index-Wextra"></a>
  311. <a name="index-Wno_002dextra"></a>
  312. <p>This enables some extra warning flags that are not enabled by
  313. <samp>-Wall</samp>. (This option used to be called <samp>-W</samp>. The older
  314. name is still supported, but the newer name is more descriptive.)
  315. </p>
  316. <div class="smallexample">
  317. <pre class="smallexample">-Wclobbered
  318. -Wcast-function-type
  319. -Wdeprecated-copy <span class="roman">(C++ only)</span>
  320. -Wempty-body
  321. -Wignored-qualifiers
  322. -Wimplicit-fallthrough=3
  323. -Wmissing-field-initializers
  324. -Wmissing-parameter-type <span class="roman">(C only)</span>
  325. -Wold-style-declaration <span class="roman">(C only)</span>
  326. -Woverride-init
  327. -Wsign-compare <span class="roman">(C only)</span>
  328. -Wstring-compare
  329. -Wredundant-move <span class="roman">(only for C++)</span>
  330. -Wtype-limits
  331. -Wuninitialized
  332. -Wshift-negative-value <span class="roman">(in C++03 and in C99 and newer)</span>
  333. -Wunused-parameter <span class="roman">(only with</span> <samp>-Wunused</samp> <span class="roman">or</span> <samp>-Wall</samp><span class="roman">)</span>
  334. -Wunused-but-set-parameter <span class="roman">(only with</span> <samp>-Wunused</samp> <span class="roman">or</span> <samp>-Wall</samp><span class="roman">)</span>
  335. </pre></div>
  336. <p>The option <samp>-Wextra</samp> also prints warning messages for the
  337. following cases:
  338. </p>
  339. <ul>
  340. <li> A pointer is compared against integer zero with <code>&lt;</code>, <code>&lt;=</code>,
  341. <code>&gt;</code>, or <code>&gt;=</code>.
  342. </li><li> (C++ only) An enumerator and a non-enumerator both appear in a
  343. conditional expression.
  344. </li><li> (C++ only) Ambiguous virtual bases.
  345. </li><li> (C++ only) Subscripting an array that has been declared <code>register</code>.
  346. </li><li> (C++ only) Taking the address of a variable that has been declared
  347. <code>register</code>.
  348. </li><li> (C++ only) A base class is not initialized in the copy constructor
  349. of a derived class.
  350. </li></ul>
  351. </dd>
  352. <dt><code>-Wabi <span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span></code></dt>
  353. <dd><a name="index-Wabi"></a>
  354. <a name="index-Wno_002dabi"></a>
  355. <p>Warn about code affected by ABI changes. This includes code that may
  356. not be compatible with the vendor-neutral C++ ABI as well as the psABI
  357. for the particular target.
  358. </p>
  359. <p>Since G++ now defaults to updating the ABI with each major release,
  360. normally <samp>-Wabi</samp> warns only about C++ ABI compatibility
  361. problems if there is a check added later in a release series for an
  362. ABI issue discovered since the initial release. <samp>-Wabi</samp> warns
  363. about more things if an older ABI version is selected (with
  364. <samp>-fabi-version=<var>n</var></samp>).
  365. </p>
  366. <p><samp>-Wabi</samp> can also be used with an explicit version number to
  367. warn about C++ ABI compatibility with a particular <samp>-fabi-version</samp>
  368. level, e.g. <samp>-Wabi=2</samp> to warn about changes relative to
  369. <samp>-fabi-version=2</samp>.
  370. </p>
  371. <p>If an explicit version number is provided and
  372. <samp>-fabi-compat-version</samp> is not specified, the version number
  373. from this option is used for compatibility aliases. If no explicit
  374. version number is provided with this option, but
  375. <samp>-fabi-compat-version</samp> is specified, that version number is
  376. used for C++ ABI warnings.
  377. </p>
  378. <p>Although an effort has been made to warn about
  379. all such cases, there are probably some cases that are not warned about,
  380. even though G++ is generating incompatible code. There may also be
  381. cases where warnings are emitted even though the code that is generated
  382. is compatible.
  383. </p>
  384. <p>You should rewrite your code to avoid these warnings if you are
  385. concerned about the fact that code generated by G++ may not be binary
  386. compatible with code generated by other compilers.
  387. </p>
  388. <p>Known incompatibilities in <samp>-fabi-version=2</samp> (which was the
  389. default from GCC 3.4 to 4.9) include:
  390. </p>
  391. <ul>
  392. <li> A template with a non-type template parameter of reference type was
  393. mangled incorrectly:
  394. <div class="smallexample">
  395. <pre class="smallexample">extern int N;
  396. template &lt;int &amp;&gt; struct S {};
  397. void n (S&lt;N&gt;) {2}
  398. </pre></div>
  399. <p>This was fixed in <samp>-fabi-version=3</samp>.
  400. </p>
  401. </li><li> SIMD vector types declared using <code>__attribute ((vector_size))</code> were
  402. mangled in a non-standard way that does not allow for overloading of
  403. functions taking vectors of different sizes.
  404. <p>The mangling was changed in <samp>-fabi-version=4</samp>.
  405. </p>
  406. </li><li> <code>__attribute ((const))</code> and <code>noreturn</code> were mangled as type
  407. qualifiers, and <code>decltype</code> of a plain declaration was folded away.
  408. <p>These mangling issues were fixed in <samp>-fabi-version=5</samp>.
  409. </p>
  410. </li><li> Scoped enumerators passed as arguments to a variadic function are
  411. promoted like unscoped enumerators, causing <code>va_arg</code> to complain.
  412. On most targets this does not actually affect the parameter passing
  413. ABI, as there is no way to pass an argument smaller than <code>int</code>.
  414. <p>Also, the ABI changed the mangling of template argument packs,
  415. <code>const_cast</code>, <code>static_cast</code>, prefix increment/decrement, and
  416. a class scope function used as a template argument.
  417. </p>
  418. <p>These issues were corrected in <samp>-fabi-version=6</samp>.
  419. </p>
  420. </li><li> Lambdas in default argument scope were mangled incorrectly, and the
  421. ABI changed the mangling of <code>nullptr_t</code>.
  422. <p>These issues were corrected in <samp>-fabi-version=7</samp>.
  423. </p>
  424. </li><li> When mangling a function type with function-cv-qualifiers, the
  425. un-qualified function type was incorrectly treated as a substitution
  426. candidate.
  427. <p>This was fixed in <samp>-fabi-version=8</samp>, the default for GCC 5.1.
  428. </p>
  429. </li><li> <code>decltype(nullptr)</code> incorrectly had an alignment of 1, leading to
  430. unaligned accesses. Note that this did not affect the ABI of a
  431. function with a <code>nullptr_t</code> parameter, as parameters have a
  432. minimum alignment.
  433. <p>This was fixed in <samp>-fabi-version=9</samp>, the default for GCC 5.2.
  434. </p>
  435. </li><li> Target-specific attributes that affect the identity of a type, such as
  436. ia32 calling conventions on a function type (stdcall, regparm, etc.),
  437. did not affect the mangled name, leading to name collisions when
  438. function pointers were used as template arguments.
  439. <p>This was fixed in <samp>-fabi-version=10</samp>, the default for GCC 6.1.
  440. </p>
  441. </li></ul>
  442. <p>This option also enables warnings about psABI-related changes.
  443. The known psABI changes at this point include:
  444. </p>
  445. <ul>
  446. <li> For SysV/x86-64, unions with <code>long double</code> members are
  447. passed in memory as specified in psABI. Prior to GCC 4.4, this was not
  448. the case. For example:
  449. <div class="smallexample">
  450. <pre class="smallexample">union U {
  451. long double ld;
  452. int i;
  453. };
  454. </pre></div>
  455. <p><code>union U</code> is now always passed in memory.
  456. </p>
  457. </li></ul>
  458. </dd>
  459. <dt><code>-Wchar-subscripts</code></dt>
  460. <dd><a name="index-Wchar_002dsubscripts"></a>
  461. <a name="index-Wno_002dchar_002dsubscripts"></a>
  462. <p>Warn if an array subscript has type <code>char</code>. This is a common cause
  463. of error, as programmers often forget that this type is signed on some
  464. machines.
  465. This warning is enabled by <samp>-Wall</samp>.
  466. </p>
  467. </dd>
  468. <dt><code>-Wno-coverage-mismatch</code></dt>
  469. <dd><a name="index-Wno_002dcoverage_002dmismatch"></a>
  470. <a name="index-Wcoverage_002dmismatch"></a>
  471. <p>Warn if feedback profiles do not match when using the
  472. <samp>-fprofile-use</samp> option.
  473. If a source file is changed between compiling with <samp>-fprofile-generate</samp>
  474. and with <samp>-fprofile-use</samp>, the files with the profile feedback can fail
  475. to match the source file and GCC cannot use the profile feedback
  476. information. By default, this warning is enabled and is treated as an
  477. error. <samp>-Wno-coverage-mismatch</samp> can be used to disable the
  478. warning or <samp>-Wno-error=coverage-mismatch</samp> can be used to
  479. disable the error. Disabling the error for this warning can result in
  480. poorly optimized code and is useful only in the
  481. case of very minor changes such as bug fixes to an existing code-base.
  482. Completely disabling the warning is not recommended.
  483. </p>
  484. </dd>
  485. <dt><code>-Wno-cpp</code></dt>
  486. <dd><p><span class="roman">(C, Objective-C, C++, Objective-C++ and Fortran only)</span>
  487. <a name="index-Wno_002dcpp"></a>
  488. <a name="index-Wcpp"></a>
  489. Suppress warning messages emitted by <code>#warning</code> directives.
  490. </p>
  491. </dd>
  492. <dt><code>-Wdouble-promotion <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  493. <dd><a name="index-Wdouble_002dpromotion"></a>
  494. <a name="index-Wno_002ddouble_002dpromotion"></a>
  495. <p>Give a warning when a value of type <code>float</code> is implicitly
  496. promoted to <code>double</code>. CPUs with a 32-bit &ldquo;single-precision&rdquo;
  497. floating-point unit implement <code>float</code> in hardware, but emulate
  498. <code>double</code> in software. On such a machine, doing computations
  499. using <code>double</code> values is much more expensive because of the
  500. overhead required for software emulation.
  501. </p>
  502. <p>It is easy to accidentally do computations with <code>double</code> because
  503. floating-point literals are implicitly of type <code>double</code>. For
  504. example, in:
  505. </p><div class="smallexample">
  506. <pre class="smallexample">float area(float radius)
  507. {
  508. return 3.14159 * radius * radius;
  509. }
  510. </pre></div>
  511. <p>the compiler performs the entire computation with <code>double</code>
  512. because the floating-point literal is a <code>double</code>.
  513. </p>
  514. </dd>
  515. <dt><code>-Wduplicate-decl-specifier <span class="roman">(C and Objective-C only)</span></code></dt>
  516. <dd><a name="index-Wduplicate_002ddecl_002dspecifier"></a>
  517. <a name="index-Wno_002dduplicate_002ddecl_002dspecifier"></a>
  518. <p>Warn if a declaration has duplicate <code>const</code>, <code>volatile</code>,
  519. <code>restrict</code> or <code>_Atomic</code> specifier. This warning is enabled by
  520. <samp>-Wall</samp>.
  521. </p>
  522. </dd>
  523. <dt><code>-Wformat</code></dt>
  524. <dt><code>-Wformat=<var>n</var></code></dt>
  525. <dd><a name="index-Wformat"></a>
  526. <a name="index-Wno_002dformat"></a>
  527. <a name="index-ffreestanding-2"></a>
  528. <a name="index-fno_002dbuiltin-1"></a>
  529. <a name="index-Wformat_003d"></a>
  530. <p>Check calls to <code>printf</code> and <code>scanf</code>, etc., to make sure that
  531. the arguments supplied have types appropriate to the format string
  532. specified, and that the conversions specified in the format string make
  533. sense. This includes standard functions, and others specified by format
  534. attributes (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>), in the <code>printf</code>,
  535. <code>scanf</code>, <code>strftime</code> and <code>strfmon</code> (an X/Open extension,
  536. not in the C standard) families (or other target-specific families).
  537. Which functions are checked without format attributes having been
  538. specified depends on the standard version selected, and such checks of
  539. functions without the attribute specified are disabled by
  540. <samp>-ffreestanding</samp> or <samp>-fno-builtin</samp>.
  541. </p>
  542. <p>The formats are checked against the format features supported by GNU
  543. libc version 2.2. These include all ISO C90 and C99 features, as well
  544. as features from the Single Unix Specification and some BSD and GNU
  545. extensions. Other library implementations may not support all these
  546. features; GCC does not support warning about features that go beyond a
  547. particular library&rsquo;s limitations. However, if <samp>-Wpedantic</samp> is used
  548. with <samp>-Wformat</samp>, warnings are given about format features not
  549. in the selected standard version (but not for <code>strfmon</code> formats,
  550. since 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>.
  551. </p>
  552. <dl compact="compact">
  553. <dt><code>-Wformat=1</code></dt>
  554. <dt><code>-Wformat</code></dt>
  555. <dd><a name="index-Wformat-1"></a>
  556. <a name="index-Wformat_003d1"></a>
  557. <p>Option <samp>-Wformat</samp> is equivalent to <samp>-Wformat=1</samp>, and
  558. <samp>-Wno-format</samp> is equivalent to <samp>-Wformat=0</samp>. Since
  559. <samp>-Wformat</samp> also checks for null format arguments for several
  560. functions, <samp>-Wformat</samp> also implies <samp>-Wnonnull</samp>. Some
  561. aspects of this level of format checking can be disabled by the
  562. options: <samp>-Wno-format-contains-nul</samp>,
  563. <samp>-Wno-format-extra-args</samp>, and <samp>-Wno-format-zero-length</samp>.
  564. <samp>-Wformat</samp> is enabled by <samp>-Wall</samp>.
  565. </p>
  566. </dd>
  567. <dt><code>-Wformat=2</code></dt>
  568. <dd><a name="index-Wformat_003d2"></a>
  569. <p>Enable <samp>-Wformat</samp> plus additional format checks. Currently
  570. equivalent to <samp>-Wformat -Wformat-nonliteral -Wformat-security
  571. -Wformat-y2k</samp>.
  572. </p></dd>
  573. </dl>
  574. </dd>
  575. <dt><code>-Wno-format-contains-nul</code></dt>
  576. <dd><a name="index-Wno_002dformat_002dcontains_002dnul"></a>
  577. <a name="index-Wformat_002dcontains_002dnul"></a>
  578. <p>If <samp>-Wformat</samp> is specified, do not warn about format strings that
  579. contain NUL bytes.
  580. </p>
  581. </dd>
  582. <dt><code>-Wno-format-extra-args</code></dt>
  583. <dd><a name="index-Wno_002dformat_002dextra_002dargs"></a>
  584. <a name="index-Wformat_002dextra_002dargs"></a>
  585. <p>If <samp>-Wformat</samp> is specified, do not warn about excess arguments to a
  586. <code>printf</code> or <code>scanf</code> format function. The C standard specifies
  587. that such arguments are ignored.
  588. </p>
  589. <p>Where the unused arguments lie between used arguments that are
  590. specified with &lsquo;<samp>$</samp>&rsquo; operand number specifications, normally
  591. warnings are still given, since the implementation could not know what
  592. type to pass to <code>va_arg</code> to skip the unused arguments. However,
  593. in the case of <code>scanf</code> formats, this option suppresses the
  594. warning if the unused arguments are all pointers, since the Single
  595. Unix Specification says that such unused arguments are allowed.
  596. </p>
  597. </dd>
  598. <dt><code>-Wformat-overflow</code></dt>
  599. <dt><code>-Wformat-overflow=<var>level</var></code></dt>
  600. <dd><a name="index-Wformat_002doverflow"></a>
  601. <a name="index-Wno_002dformat_002doverflow"></a>
  602. <p>Warn about calls to formatted input/output functions such as <code>sprintf</code>
  603. and <code>vsprintf</code> that might overflow the destination buffer. When the
  604. exact number of bytes written by a format directive cannot be determined
  605. at compile-time it is estimated based on heuristics that depend on the
  606. <var>level</var> argument and on optimization. While enabling optimization
  607. will in most cases improve the accuracy of the warning, it may also
  608. result in false positives.
  609. </p>
  610. <dl compact="compact">
  611. <dt><code>-Wformat-overflow</code></dt>
  612. <dt><code>-Wformat-overflow=1</code></dt>
  613. <dd><a name="index-Wformat_002doverflow-1"></a>
  614. <a name="index-Wno_002dformat_002doverflow-1"></a>
  615. <p>Level <var>1</var> of <samp>-Wformat-overflow</samp> enabled by <samp>-Wformat</samp>
  616. employs a conservative approach that warns only about calls that most
  617. likely overflow the buffer. At this level, numeric arguments to format
  618. directives with unknown values are assumed to have the value of one, and
  619. strings of unknown length to be empty. Numeric arguments that are known
  620. to be bounded to a subrange of their type, or string arguments whose output
  621. is bounded either by their directive&rsquo;s precision or by a finite set of
  622. string literals, are assumed to take on the value within the range that
  623. results in the most bytes on output. For example, the call to <code>sprintf</code>
  624. below is diagnosed because even with both <var>a</var> and <var>b</var> equal to zero,
  625. the terminating NUL character (<code>'\0'</code>) appended by the function
  626. to the destination buffer will be written past its end. Increasing
  627. the size of the buffer by a single byte is sufficient to avoid the
  628. warning, though it may not be sufficient to avoid the overflow.
  629. </p>
  630. <div class="smallexample">
  631. <pre class="smallexample">void f (int a, int b)
  632. {
  633. char buf [13];
  634. sprintf (buf, &quot;a = %i, b = %i\n&quot;, a, b);
  635. }
  636. </pre></div>
  637. </dd>
  638. <dt><code>-Wformat-overflow=2</code></dt>
  639. <dd><p>Level <var>2</var> warns also about calls that might overflow the destination
  640. buffer given an argument of sufficient length or magnitude. At level
  641. <var>2</var>, unknown numeric arguments are assumed to have the minimum
  642. representable value for signed types with a precision greater than 1, and
  643. the maximum representable value otherwise. Unknown string arguments whose
  644. length cannot be assumed to be bounded either by the directive&rsquo;s precision,
  645. or by a finite set of string literals they may evaluate to, or the character
  646. array they may point to, are assumed to be 1 character long.
  647. </p>
  648. <p>At level <var>2</var>, the call in the example above is again diagnosed, but
  649. this time because with <var>a</var> equal to a 32-bit <code>INT_MIN</code> the first
  650. <code>%i</code> directive will write some of its digits beyond the end of
  651. the destination buffer. To make the call safe regardless of the values
  652. of the two variables, the size of the destination buffer must be increased
  653. to at least 34 bytes. GCC includes the minimum size of the buffer in
  654. an informational note following the warning.
  655. </p>
  656. <p>An alternative to increasing the size of the destination buffer is to
  657. constrain the range of formatted values. The maximum length of string
  658. arguments can be bounded by specifying the precision in the format
  659. directive. When numeric arguments of format directives can be assumed
  660. to be bounded by less than the precision of their type, choosing
  661. an appropriate length modifier to the format specifier will reduce
  662. the required buffer size. For example, if <var>a</var> and <var>b</var> in the
  663. example above can be assumed to be within the precision of
  664. the <code>short int</code> type then using either the <code>%hi</code> format
  665. directive or casting the argument to <code>short</code> reduces the maximum
  666. required size of the buffer to 24 bytes.
  667. </p>
  668. <div class="smallexample">
  669. <pre class="smallexample">void f (int a, int b)
  670. {
  671. char buf [23];
  672. sprintf (buf, &quot;a = %hi, b = %i\n&quot;, a, (short)b);
  673. }
  674. </pre></div>
  675. </dd>
  676. </dl>
  677. </dd>
  678. <dt><code>-Wno-format-zero-length</code></dt>
  679. <dd><a name="index-Wno_002dformat_002dzero_002dlength"></a>
  680. <a name="index-Wformat_002dzero_002dlength"></a>
  681. <p>If <samp>-Wformat</samp> is specified, do not warn about zero-length formats.
  682. The C standard specifies that zero-length formats are allowed.
  683. </p>
  684. </dd>
  685. <dt><code>-Wformat-nonliteral</code></dt>
  686. <dd><a name="index-Wformat_002dnonliteral"></a>
  687. <a name="index-Wno_002dformat_002dnonliteral"></a>
  688. <p>If <samp>-Wformat</samp> is specified, also warn if the format string is not a
  689. string literal and so cannot be checked, unless the format function
  690. takes its format arguments as a <code>va_list</code>.
  691. </p>
  692. </dd>
  693. <dt><code>-Wformat-security</code></dt>
  694. <dd><a name="index-Wformat_002dsecurity"></a>
  695. <a name="index-Wno_002dformat_002dsecurity"></a>
  696. <p>If <samp>-Wformat</samp> is specified, also warn about uses of format
  697. functions that represent possible security problems. At present, this
  698. warns about calls to <code>printf</code> and <code>scanf</code> functions where the
  699. format string is not a string literal and there are no format arguments,
  700. as in <code>printf (foo);</code>. This may be a security hole if the format
  701. string came from untrusted input and contains &lsquo;<samp>%n</samp>&rsquo;. (This is
  702. currently a subset of what <samp>-Wformat-nonliteral</samp> warns about, but
  703. in future warnings may be added to <samp>-Wformat-security</samp> that are not
  704. included in <samp>-Wformat-nonliteral</samp>.)
  705. </p>
  706. </dd>
  707. <dt><code>-Wformat-signedness</code></dt>
  708. <dd><a name="index-Wformat_002dsignedness"></a>
  709. <a name="index-Wno_002dformat_002dsignedness"></a>
  710. <p>If <samp>-Wformat</samp> is specified, also warn if the format string
  711. requires an unsigned argument and the argument is signed and vice versa.
  712. </p>
  713. </dd>
  714. <dt><code>-Wformat-truncation</code></dt>
  715. <dt><code>-Wformat-truncation=<var>level</var></code></dt>
  716. <dd><a name="index-Wformat_002dtruncation"></a>
  717. <a name="index-Wno_002dformat_002dtruncation"></a>
  718. <p>Warn about calls to formatted input/output functions such as <code>snprintf</code>
  719. and <code>vsnprintf</code> that might result in output truncation. When the exact
  720. number of bytes written by a format directive cannot be determined at
  721. compile-time it is estimated based on heuristics that depend on
  722. the <var>level</var> argument and on optimization. While enabling optimization
  723. will in most cases improve the accuracy of the warning, it may also result
  724. in false positives. Except as noted otherwise, the option uses the same
  725. logic <samp>-Wformat-overflow</samp>.
  726. </p>
  727. <dl compact="compact">
  728. <dt><code>-Wformat-truncation</code></dt>
  729. <dt><code>-Wformat-truncation=1</code></dt>
  730. <dd><a name="index-Wformat_002dtruncation-1"></a>
  731. <a name="index-Wno_002dformat_002dtruncation-1"></a>
  732. <p>Level <var>1</var> of <samp>-Wformat-truncation</samp> enabled by <samp>-Wformat</samp>
  733. employs a conservative approach that warns only about calls to bounded
  734. functions whose return value is unused and that will most likely result
  735. in output truncation.
  736. </p>
  737. </dd>
  738. <dt><code>-Wformat-truncation=2</code></dt>
  739. <dd><p>Level <var>2</var> warns also about calls to bounded functions whose return
  740. value is used and that might result in truncation given an argument of
  741. sufficient length or magnitude.
  742. </p></dd>
  743. </dl>
  744. </dd>
  745. <dt><code>-Wformat-y2k</code></dt>
  746. <dd><a name="index-Wformat_002dy2k"></a>
  747. <a name="index-Wno_002dformat_002dy2k"></a>
  748. <p>If <samp>-Wformat</samp> is specified, also warn about <code>strftime</code>
  749. formats that may yield only a two-digit year.
  750. </p>
  751. </dd>
  752. <dt><code>-Wnonnull</code></dt>
  753. <dd><a name="index-Wnonnull"></a>
  754. <a name="index-Wno_002dnonnull"></a>
  755. <p>Warn about passing a null pointer for arguments marked as
  756. requiring a non-null value by the <code>nonnull</code> function attribute.
  757. </p>
  758. <p><samp>-Wnonnull</samp> is included in <samp>-Wall</samp> and <samp>-Wformat</samp>. It
  759. can be disabled with the <samp>-Wno-nonnull</samp> option.
  760. </p>
  761. </dd>
  762. <dt><code>-Wnonnull-compare</code></dt>
  763. <dd><a name="index-Wnonnull_002dcompare"></a>
  764. <a name="index-Wno_002dnonnull_002dcompare"></a>
  765. <p>Warn when comparing an argument marked with the <code>nonnull</code>
  766. function attribute against null inside the function.
  767. </p>
  768. <p><samp>-Wnonnull-compare</samp> is included in <samp>-Wall</samp>. It
  769. can be disabled with the <samp>-Wno-nonnull-compare</samp> option.
  770. </p>
  771. </dd>
  772. <dt><code>-Wnull-dereference</code></dt>
  773. <dd><a name="index-Wnull_002ddereference"></a>
  774. <a name="index-Wno_002dnull_002ddereference"></a>
  775. <p>Warn if the compiler detects paths that trigger erroneous or
  776. undefined behavior due to dereferencing a null pointer. This option
  777. is only active when <samp>-fdelete-null-pointer-checks</samp> is active,
  778. which is enabled by optimizations in most targets. The precision of
  779. the warnings depends on the optimization options used.
  780. </p>
  781. </dd>
  782. <dt><code>-Winit-self <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  783. <dd><a name="index-Winit_002dself"></a>
  784. <a name="index-Wno_002dinit_002dself"></a>
  785. <p>Warn about uninitialized variables that are initialized with themselves.
  786. Note this option can only be used with the <samp>-Wuninitialized</samp> option.
  787. </p>
  788. <p>For example, GCC warns about <code>i</code> being uninitialized in the
  789. following snippet only when <samp>-Winit-self</samp> has been specified:
  790. </p><div class="smallexample">
  791. <pre class="smallexample">int f()
  792. {
  793. int i = i;
  794. return i;
  795. }
  796. </pre></div>
  797. <p>This warning is enabled by <samp>-Wall</samp> in C++.
  798. </p>
  799. </dd>
  800. <dt><code>-Wno-implicit-int <span class="roman">(C and Objective-C only)</span></code></dt>
  801. <dd><a name="index-Wimplicit_002dint"></a>
  802. <a name="index-Wno_002dimplicit_002dint"></a>
  803. <p>This option controls warnings when a declaration does not specify a type.
  804. This warning is enabled by default in C99 and later dialects of C,
  805. and also by <samp>-Wall</samp>.
  806. </p>
  807. </dd>
  808. <dt><code>-Wno-implicit-function-declaration <span class="roman">(C and Objective-C only)</span></code></dt>
  809. <dd><a name="index-Wimplicit_002dfunction_002ddeclaration"></a>
  810. <a name="index-Wno_002dimplicit_002dfunction_002ddeclaration"></a>
  811. <p>This option controls warnings when a function is used before being declared.
  812. This warning is enabled by default in C99 and later dialects of C,
  813. and also by <samp>-Wall</samp>.
  814. The warning is made into an error by <samp>-pedantic-errors</samp>.
  815. </p>
  816. </dd>
  817. <dt><code>-Wimplicit <span class="roman">(C and Objective-C only)</span></code></dt>
  818. <dd><a name="index-Wimplicit"></a>
  819. <a name="index-Wno_002dimplicit"></a>
  820. <p>Same as <samp>-Wimplicit-int</samp> and <samp>-Wimplicit-function-declaration</samp>.
  821. This warning is enabled by <samp>-Wall</samp>.
  822. </p>
  823. </dd>
  824. <dt><code>-Wimplicit-fallthrough</code></dt>
  825. <dd><a name="index-Wimplicit_002dfallthrough"></a>
  826. <a name="index-Wno_002dimplicit_002dfallthrough"></a>
  827. <p><samp>-Wimplicit-fallthrough</samp> is the same as <samp>-Wimplicit-fallthrough=3</samp>
  828. and <samp>-Wno-implicit-fallthrough</samp> is the same as
  829. <samp>-Wimplicit-fallthrough=0</samp>.
  830. </p>
  831. </dd>
  832. <dt><code>-Wimplicit-fallthrough=<var>n</var></code></dt>
  833. <dd><a name="index-Wimplicit_002dfallthrough_003d"></a>
  834. <p>Warn when a switch case falls through. For example:
  835. </p>
  836. <div class="smallexample">
  837. <pre class="smallexample">switch (cond)
  838. {
  839. case 1:
  840. a = 1;
  841. break;
  842. case 2:
  843. a = 2;
  844. case 3:
  845. a = 3;
  846. break;
  847. }
  848. </pre></div>
  849. <p>This warning does not warn when the last statement of a case cannot
  850. fall through, e.g. when there is a return statement or a call to function
  851. declared with the noreturn attribute. <samp>-Wimplicit-fallthrough=</samp>
  852. also takes into account control flow statements, such as ifs, and only
  853. warns when appropriate. E.g.
  854. </p>
  855. <div class="smallexample">
  856. <pre class="smallexample">switch (cond)
  857. {
  858. case 1:
  859. if (i &gt; 3) {
  860. bar (5);
  861. break;
  862. } else if (i &lt; 1) {
  863. bar (0);
  864. } else
  865. return;
  866. default:
  867. &hellip;
  868. }
  869. </pre></div>
  870. <p>Since there are occasions where a switch case fall through is desirable,
  871. GCC provides an attribute, <code>__attribute__ ((fallthrough))</code>, that is
  872. to be used along with a null statement to suppress this warning that
  873. would normally occur:
  874. </p>
  875. <div class="smallexample">
  876. <pre class="smallexample">switch (cond)
  877. {
  878. case 1:
  879. bar (0);
  880. __attribute__ ((fallthrough));
  881. default:
  882. &hellip;
  883. }
  884. </pre></div>
  885. <p>C++17 provides a standard way to suppress the <samp>-Wimplicit-fallthrough</samp>
  886. warning using <code>[[fallthrough]];</code> instead of the GNU attribute. In C++11
  887. or C++14 users can use <code>[[gnu::fallthrough]];</code>, which is a GNU extension.
  888. Instead of these attributes, it is also possible to add a fallthrough comment
  889. to silence the warning. The whole body of the C or C++ style comment should
  890. match the given regular expressions listed below. The option argument <var>n</var>
  891. specifies what kind of comments are accepted:
  892. </p>
  893. <ul>
  894. <li> <samp>-Wimplicit-fallthrough=0</samp> disables the warning altogether.
  895. </li><li> <samp>-Wimplicit-fallthrough=1</samp> matches <code>.*</code> regular
  896. expression, any comment is used as fallthrough comment.
  897. </li><li> <samp>-Wimplicit-fallthrough=2</samp> case insensitively matches
  898. <code>.*falls?[ \t-]*thr(ough|u).*</code> regular expression.
  899. </li><li> <samp>-Wimplicit-fallthrough=3</samp> case sensitively matches one of the
  900. following regular expressions:
  901. <ul>
  902. <li> <code>-fallthrough</code>
  903. </li><li> <code>@fallthrough@</code>
  904. </li><li> <code>lint -fallthrough[ \t]*</code>
  905. </li><li> <code>[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?<br>FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?</code>
  906. </li><li> <code>[ \t.!]*(Else,? |Intentional(ly)? )?<br>Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?</code>
  907. </li><li> <code>[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?<br>fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?</code>
  908. </li></ul>
  909. </li><li> <samp>-Wimplicit-fallthrough=4</samp> case sensitively matches one of the
  910. following regular expressions:
  911. <ul>
  912. <li> <code>-fallthrough</code>
  913. </li><li> <code>@fallthrough@</code>
  914. </li><li> <code>lint -fallthrough[ \t]*</code>
  915. </li><li> <code>[ \t]*FALLTHR(OUGH|U)[ \t]*</code>
  916. </li></ul>
  917. </li><li> <samp>-Wimplicit-fallthrough=5</samp> doesn&rsquo;t recognize any comments as
  918. fallthrough comments, only attributes disable the warning.
  919. </li></ul>
  920. <p>The comment needs to be followed after optional whitespace and other comments
  921. by <code>case</code> or <code>default</code> keywords or by a user label that precedes some
  922. <code>case</code> or <code>default</code> label.
  923. </p>
  924. <div class="smallexample">
  925. <pre class="smallexample">switch (cond)
  926. {
  927. case 1:
  928. bar (0);
  929. /* FALLTHRU */
  930. default:
  931. &hellip;
  932. }
  933. </pre></div>
  934. <p>The <samp>-Wimplicit-fallthrough=3</samp> warning is enabled by <samp>-Wextra</samp>.
  935. </p>
  936. </dd>
  937. <dt><code>-Wno-if-not-aligned <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  938. <dd><a name="index-Wif_002dnot_002daligned"></a>
  939. <a name="index-Wno_002dif_002dnot_002daligned"></a>
  940. <p>Control if warnings triggered by the <code>warn_if_not_aligned</code> attribute
  941. should be issued. These warnings are enabled by default.
  942. </p>
  943. </dd>
  944. <dt><code>-Wignored-qualifiers <span class="roman">(C and C++ only)</span></code></dt>
  945. <dd><a name="index-Wignored_002dqualifiers"></a>
  946. <a name="index-Wno_002dignored_002dqualifiers"></a>
  947. <p>Warn if the return type of a function has a type qualifier
  948. such as <code>const</code>. For ISO C such a type qualifier has no effect,
  949. since the value returned by a function is not an lvalue.
  950. For C++, the warning is only emitted for scalar types or <code>void</code>.
  951. ISO C prohibits qualified <code>void</code> return types on function
  952. definitions, so such return types always receive a warning
  953. even without this option.
  954. </p>
  955. <p>This warning is also enabled by <samp>-Wextra</samp>.
  956. </p>
  957. </dd>
  958. <dt><code>-Wno-ignored-attributes <span class="roman">(C and C++ only)</span></code></dt>
  959. <dd><a name="index-Wignored_002dattributes"></a>
  960. <a name="index-Wno_002dignored_002dattributes"></a>
  961. <p>This option controls warnings when an attribute is ignored.
  962. This is different from the
  963. <samp>-Wattributes</samp> option in that it warns whenever the compiler decides
  964. to drop an attribute, not that the attribute is either unknown, used in a
  965. wrong place, etc. This warning is enabled by default.
  966. </p>
  967. </dd>
  968. <dt><code>-Wmain</code></dt>
  969. <dd><a name="index-Wmain"></a>
  970. <a name="index-Wno_002dmain"></a>
  971. <p>Warn if the type of <code>main</code> is suspicious. <code>main</code> should be
  972. a function with external linkage, returning int, taking either zero
  973. arguments, two, or three arguments of appropriate types. This warning
  974. is enabled by default in C++ and is enabled by either <samp>-Wall</samp>
  975. or <samp>-Wpedantic</samp>.
  976. </p>
  977. </dd>
  978. <dt><code>-Wmisleading-indentation <span class="roman">(C and C++ only)</span></code></dt>
  979. <dd><a name="index-Wmisleading_002dindentation"></a>
  980. <a name="index-Wno_002dmisleading_002dindentation"></a>
  981. <p>Warn when the indentation of the code does not reflect the block structure.
  982. Specifically, a warning is issued for <code>if</code>, <code>else</code>, <code>while</code>, and
  983. <code>for</code> clauses with a guarded statement that does not use braces,
  984. followed by an unguarded statement with the same indentation.
  985. </p>
  986. <p>In the following example, the call to &ldquo;bar&rdquo; is misleadingly indented as
  987. if it were guarded by the &ldquo;if&rdquo; conditional.
  988. </p>
  989. <div class="smallexample">
  990. <pre class="smallexample"> if (some_condition ())
  991. foo ();
  992. bar (); /* Gotcha: this is not guarded by the &quot;if&quot;. */
  993. </pre></div>
  994. <p>In the case of mixed tabs and spaces, the warning uses the
  995. <samp>-ftabstop=</samp> option to determine if the statements line up
  996. (defaulting to 8).
  997. </p>
  998. <p>The warning is not issued for code involving multiline preprocessor logic
  999. such as the following example.
  1000. </p>
  1001. <div class="smallexample">
  1002. <pre class="smallexample"> if (flagA)
  1003. foo (0);
  1004. #if SOME_CONDITION_THAT_DOES_NOT_HOLD
  1005. if (flagB)
  1006. #endif
  1007. foo (1);
  1008. </pre></div>
  1009. <p>The warning is not issued after a <code>#line</code> directive, since this
  1010. typically indicates autogenerated code, and no assumptions can be made
  1011. about the layout of the file that the directive references.
  1012. </p>
  1013. <p>This warning is enabled by <samp>-Wall</samp> in C and C++.
  1014. </p>
  1015. </dd>
  1016. <dt><code>-Wmissing-attributes</code></dt>
  1017. <dd><a name="index-Wmissing_002dattributes"></a>
  1018. <a name="index-Wno_002dmissing_002dattributes"></a>
  1019. <p>Warn when a declaration of a function is missing one or more attributes
  1020. that a related function is declared with and whose absence may adversely
  1021. affect the correctness or efficiency of generated code. For example,
  1022. the warning is issued for declarations of aliases that use attributes
  1023. to specify less restrictive requirements than those of their targets.
  1024. This typically represents a potential optimization opportunity.
  1025. By contrast, the <samp>-Wattribute-alias=2</samp> option controls warnings
  1026. issued when the alias is more restrictive than the target, which could
  1027. lead to incorrect code generation.
  1028. Attributes considered include <code>alloc_align</code>, <code>alloc_size</code>,
  1029. <code>cold</code>, <code>const</code>, <code>hot</code>, <code>leaf</code>, <code>malloc</code>,
  1030. <code>nonnull</code>, <code>noreturn</code>, <code>nothrow</code>, <code>pure</code>,
  1031. <code>returns_nonnull</code>, and <code>returns_twice</code>.
  1032. </p>
  1033. <p>In C++, the warning is issued when an explicit specialization of a primary
  1034. template declared with attribute <code>alloc_align</code>, <code>alloc_size</code>,
  1035. <code>assume_aligned</code>, <code>format</code>, <code>format_arg</code>, <code>malloc</code>,
  1036. or <code>nonnull</code> is declared without it. Attributes <code>deprecated</code>,
  1037. <code>error</code>, and <code>warning</code> suppress the warning.
  1038. (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>).
  1039. </p>
  1040. <p>You can use the <code>copy</code> attribute to apply the same
  1041. set of attributes to a declaration as that on another declaration without
  1042. explicitly enumerating the attributes. This attribute can be applied
  1043. to declarations of functions (see <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>),
  1044. variables (see <a href="Common-Variable-Attributes.html#Common-Variable-Attributes">Common Variable Attributes</a>), or types
  1045. (see <a href="Common-Type-Attributes.html#Common-Type-Attributes">Common Type Attributes</a>).
  1046. </p>
  1047. <p><samp>-Wmissing-attributes</samp> is enabled by <samp>-Wall</samp>.
  1048. </p>
  1049. <p>For example, since the declaration of the primary function template
  1050. below makes use of both attribute <code>malloc</code> and <code>alloc_size</code>
  1051. the declaration of the explicit specialization of the template is
  1052. diagnosed because it is missing one of the attributes.
  1053. </p>
  1054. <div class="smallexample">
  1055. <pre class="smallexample">template &lt;class T&gt;
  1056. T* __attribute__ ((malloc, alloc_size (1)))
  1057. allocate (size_t);
  1058. template &lt;&gt;
  1059. void* __attribute__ ((malloc)) // missing alloc_size
  1060. allocate&lt;void&gt; (size_t);
  1061. </pre></div>
  1062. </dd>
  1063. <dt><code>-Wmissing-braces</code></dt>
  1064. <dd><a name="index-Wmissing_002dbraces"></a>
  1065. <a name="index-Wno_002dmissing_002dbraces"></a>
  1066. <p>Warn if an aggregate or union initializer is not fully bracketed. In
  1067. the following example, the initializer for <code>a</code> is not fully
  1068. bracketed, but that for <code>b</code> is fully bracketed.
  1069. </p>
  1070. <div class="smallexample">
  1071. <pre class="smallexample">int a[2][2] = { 0, 1, 2, 3 };
  1072. int b[2][2] = { { 0, 1 }, { 2, 3 } };
  1073. </pre></div>
  1074. <p>This warning is enabled by <samp>-Wall</samp>.
  1075. </p>
  1076. </dd>
  1077. <dt><code>-Wmissing-include-dirs <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  1078. <dd><a name="index-Wmissing_002dinclude_002ddirs"></a>
  1079. <a name="index-Wno_002dmissing_002dinclude_002ddirs"></a>
  1080. <p>Warn if a user-supplied include directory does not exist.
  1081. </p>
  1082. </dd>
  1083. <dt><code>-Wno-missing-profile</code></dt>
  1084. <dd><a name="index-Wmissing_002dprofile"></a>
  1085. <a name="index-Wno_002dmissing_002dprofile"></a>
  1086. <p>This option controls warnings if feedback profiles are missing when using the
  1087. <samp>-fprofile-use</samp> option.
  1088. This option diagnoses those cases where a new function or a new file is added
  1089. between compiling with <samp>-fprofile-generate</samp> and with
  1090. <samp>-fprofile-use</samp>, without regenerating the profiles.
  1091. In these cases, the profile feedback data files do not contain any
  1092. profile feedback information for
  1093. the newly added function or file respectively. Also, in the case when profile
  1094. count data (.gcda) files are removed, GCC cannot use any profile feedback
  1095. information. In all these cases, warnings are issued to inform you that a
  1096. profile generation step is due.
  1097. Ignoring the warning can result in poorly optimized code.
  1098. <samp>-Wno-missing-profile</samp> can be used to
  1099. disable the warning, but this is not recommended and should be done only
  1100. when non-existent profile data is justified.
  1101. </p>
  1102. </dd>
  1103. <dt><code>-Wmultistatement-macros</code></dt>
  1104. <dd><a name="index-Wmultistatement_002dmacros"></a>
  1105. <a name="index-Wno_002dmultistatement_002dmacros"></a>
  1106. <p>Warn about unsafe multiple statement macros that appear to be guarded
  1107. by a clause such as <code>if</code>, <code>else</code>, <code>for</code>, <code>switch</code>, or
  1108. <code>while</code>, in which only the first statement is actually guarded after
  1109. the macro is expanded.
  1110. </p>
  1111. <p>For example:
  1112. </p>
  1113. <div class="smallexample">
  1114. <pre class="smallexample">#define DOIT x++; y++
  1115. if (c)
  1116. DOIT;
  1117. </pre></div>
  1118. <p>will increment <code>y</code> unconditionally, not just when <code>c</code> holds.
  1119. The can usually be fixed by wrapping the macro in a do-while loop:
  1120. </p><div class="smallexample">
  1121. <pre class="smallexample">#define DOIT do { x++; y++; } while (0)
  1122. if (c)
  1123. DOIT;
  1124. </pre></div>
  1125. <p>This warning is enabled by <samp>-Wall</samp> in C and C++.
  1126. </p>
  1127. </dd>
  1128. <dt><code>-Wparentheses</code></dt>
  1129. <dd><a name="index-Wparentheses"></a>
  1130. <a name="index-Wno_002dparentheses"></a>
  1131. <p>Warn if parentheses are omitted in certain contexts, such
  1132. as when there is an assignment in a context where a truth value
  1133. is expected, or when operators are nested whose precedence people
  1134. often get confused about.
  1135. </p>
  1136. <p>Also warn if a comparison like <code>x&lt;=y&lt;=z</code> appears; this is
  1137. equivalent to <code>(x&lt;=y ? 1 : 0) &lt;= z</code>, which is a different
  1138. interpretation from that of ordinary mathematical notation.
  1139. </p>
  1140. <p>Also warn for dangerous uses of the GNU extension to
  1141. <code>?:</code> with omitted middle operand. When the condition
  1142. in the <code>?</code>: operator is a boolean expression, the omitted value is
  1143. always 1. Often programmers expect it to be a value computed
  1144. inside the conditional expression instead.
  1145. </p>
  1146. <p>For C++ this also warns for some cases of unnecessary parentheses in
  1147. declarations, which can indicate an attempt at a function call instead
  1148. of a declaration:
  1149. </p><div class="smallexample">
  1150. <pre class="smallexample">{
  1151. // Declares a local variable called mymutex.
  1152. std::unique_lock&lt;std::mutex&gt; (mymutex);
  1153. // User meant std::unique_lock&lt;std::mutex&gt; lock (mymutex);
  1154. }
  1155. </pre></div>
  1156. <p>This warning is enabled by <samp>-Wall</samp>.
  1157. </p>
  1158. </dd>
  1159. <dt><code>-Wsequence-point</code></dt>
  1160. <dd><a name="index-Wsequence_002dpoint"></a>
  1161. <a name="index-Wno_002dsequence_002dpoint"></a>
  1162. <p>Warn about code that may have undefined semantics because of violations
  1163. of sequence point rules in the C and C++ standards.
  1164. </p>
  1165. <p>The C and C++ standards define the order in which expressions in a C/C++
  1166. program are evaluated in terms of <em>sequence points</em>, which represent
  1167. a partial ordering between the execution of parts of the program: those
  1168. executed before the sequence point, and those executed after it. These
  1169. occur after the evaluation of a full expression (one which is not part
  1170. of a larger expression), after the evaluation of the first operand of a
  1171. <code>&amp;&amp;</code>, <code>||</code>, <code>? :</code> or <code>,</code> (comma) operator, before a
  1172. function is called (but after the evaluation of its arguments and the
  1173. expression denoting the called function), and in certain other places.
  1174. Other than as expressed by the sequence point rules, the order of
  1175. evaluation of subexpressions of an expression is not specified. All
  1176. these rules describe only a partial order rather than a total order,
  1177. since, for example, if two functions are called within one expression
  1178. with no sequence point between them, the order in which the functions
  1179. are called is not specified. However, the standards committee have
  1180. ruled that function calls do not overlap.
  1181. </p>
  1182. <p>It is not specified when between sequence points modifications to the
  1183. values of objects take effect. Programs whose behavior depends on this
  1184. have undefined behavior; the C and C++ standards specify that &ldquo;Between
  1185. the previous and next sequence point an object shall have its stored
  1186. value modified at most once by the evaluation of an expression.
  1187. Furthermore, the prior value shall be read only to determine the value
  1188. to be stored.&rdquo;. If a program breaks these rules, the results on any
  1189. particular implementation are entirely unpredictable.
  1190. </p>
  1191. <p>Examples of code with undefined behavior are <code>a = a++;</code>, <code>a[n]
  1192. = b[n++]</code> and <code>a[i++] = i;</code>. Some more complicated cases are not
  1193. diagnosed by this option, and it may give an occasional false positive
  1194. result, but in general it has been found fairly effective at detecting
  1195. this sort of problem in programs.
  1196. </p>
  1197. <p>The C++17 standard will define the order of evaluation of operands in
  1198. more cases: in particular it requires that the right-hand side of an
  1199. assignment be evaluated before the left-hand side, so the above
  1200. examples are no longer undefined. But this option will still warn
  1201. about them, to help people avoid writing code that is undefined in C
  1202. and earlier revisions of C++.
  1203. </p>
  1204. <p>The standard is worded confusingly, therefore there is some debate
  1205. over the precise meaning of the sequence point rules in subtle cases.
  1206. Links to discussions of the problem, including proposed formal
  1207. definitions, may be found on the GCC readings page, at
  1208. <a href="http://gcc.gnu.org/readings.html">http://gcc.gnu.org/readings.html</a>.
  1209. </p>
  1210. <p>This warning is enabled by <samp>-Wall</samp> for C and C++.
  1211. </p>
  1212. </dd>
  1213. <dt><code>-Wno-return-local-addr</code></dt>
  1214. <dd><a name="index-Wno_002dreturn_002dlocal_002daddr"></a>
  1215. <a name="index-Wreturn_002dlocal_002daddr"></a>
  1216. <p>Do not warn about returning a pointer (or in C++, a reference) to a
  1217. variable that goes out of scope after the function returns.
  1218. </p>
  1219. </dd>
  1220. <dt><code>-Wreturn-type</code></dt>
  1221. <dd><a name="index-Wreturn_002dtype"></a>
  1222. <a name="index-Wno_002dreturn_002dtype"></a>
  1223. <p>Warn whenever a function is defined with a return type that defaults
  1224. to <code>int</code>. Also warn about any <code>return</code> statement with no
  1225. return value in a function whose return type is not <code>void</code>
  1226. (falling off the end of the function body is considered returning
  1227. without a value).
  1228. </p>
  1229. <p>For C only, warn about a <code>return</code> statement with an expression in a
  1230. function whose return type is <code>void</code>, unless the expression type is
  1231. also <code>void</code>. As a GNU extension, the latter case is accepted
  1232. without a warning unless <samp>-Wpedantic</samp> is used. Attempting
  1233. to use the return value of a non-<code>void</code> function other than <code>main</code>
  1234. that flows off the end by reaching the closing curly brace that terminates
  1235. the function is undefined.
  1236. </p>
  1237. <p>Unlike in C, in C++, flowing off the end of a non-<code>void</code> function other
  1238. than <code>main</code> results in undefined behavior even when the value of
  1239. the function is not used.
  1240. </p>
  1241. <p>This warning is enabled by default in C++ and by <samp>-Wall</samp> otherwise.
  1242. </p>
  1243. </dd>
  1244. <dt><code>-Wno-shift-count-negative</code></dt>
  1245. <dd><a name="index-Wshift_002dcount_002dnegative"></a>
  1246. <a name="index-Wno_002dshift_002dcount_002dnegative"></a>
  1247. <p>Controls warnings if a shift count is negative.
  1248. This warning is enabled by default.
  1249. </p>
  1250. </dd>
  1251. <dt><code>-Wno-shift-count-overflow</code></dt>
  1252. <dd><a name="index-Wshift_002dcount_002doverflow"></a>
  1253. <a name="index-Wno_002dshift_002dcount_002doverflow"></a>
  1254. <p>Controls warnings if a shift count is greater than or equal to the bit width
  1255. of the type. This warning is enabled by default.
  1256. </p>
  1257. </dd>
  1258. <dt><code>-Wshift-negative-value</code></dt>
  1259. <dd><a name="index-Wshift_002dnegative_002dvalue"></a>
  1260. <a name="index-Wno_002dshift_002dnegative_002dvalue"></a>
  1261. <p>Warn if left shifting a negative value. This warning is enabled by
  1262. <samp>-Wextra</samp> in C99 and C++11 modes (and newer).
  1263. </p>
  1264. </dd>
  1265. <dt><code>-Wno-shift-overflow</code></dt>
  1266. <dt><code>-Wshift-overflow=<var>n</var></code></dt>
  1267. <dd><a name="index-Wshift_002doverflow"></a>
  1268. <a name="index-Wno_002dshift_002doverflow"></a>
  1269. <p>These options control warnings about left shift overflows.
  1270. </p>
  1271. <dl compact="compact">
  1272. <dt><code>-Wshift-overflow=1</code></dt>
  1273. <dd><p>This is the warning level of <samp>-Wshift-overflow</samp> and is enabled
  1274. by default in C99 and C++11 modes (and newer). This warning level does
  1275. not warn about left-shifting 1 into the sign bit. (However, in C, such
  1276. an overflow is still rejected in contexts where an integer constant expression
  1277. is required.) No warning is emitted in C++2A mode (and newer), as signed left
  1278. shifts always wrap.
  1279. </p>
  1280. </dd>
  1281. <dt><code>-Wshift-overflow=2</code></dt>
  1282. <dd><p>This warning level also warns about left-shifting 1 into the sign bit,
  1283. unless C++14 mode (or newer) is active.
  1284. </p></dd>
  1285. </dl>
  1286. </dd>
  1287. <dt><code>-Wswitch</code></dt>
  1288. <dd><a name="index-Wswitch"></a>
  1289. <a name="index-Wno_002dswitch"></a>
  1290. <p>Warn whenever a <code>switch</code> statement has an index of enumerated type
  1291. and lacks a <code>case</code> for one or more of the named codes of that
  1292. enumeration. (The presence of a <code>default</code> label prevents this
  1293. warning.) <code>case</code> labels outside the enumeration range also
  1294. provoke warnings when this option is used (even if there is a
  1295. <code>default</code> label).
  1296. This warning is enabled by <samp>-Wall</samp>.
  1297. </p>
  1298. </dd>
  1299. <dt><code>-Wswitch-default</code></dt>
  1300. <dd><a name="index-Wswitch_002ddefault"></a>
  1301. <a name="index-Wno_002dswitch_002ddefault"></a>
  1302. <p>Warn whenever a <code>switch</code> statement does not have a <code>default</code>
  1303. case.
  1304. </p>
  1305. </dd>
  1306. <dt><code>-Wswitch-enum</code></dt>
  1307. <dd><a name="index-Wswitch_002denum"></a>
  1308. <a name="index-Wno_002dswitch_002denum"></a>
  1309. <p>Warn whenever a <code>switch</code> statement has an index of enumerated type
  1310. and lacks a <code>case</code> for one or more of the named codes of that
  1311. enumeration. <code>case</code> labels outside the enumeration range also
  1312. provoke warnings when this option is used. The only difference
  1313. between <samp>-Wswitch</samp> and this option is that this option gives a
  1314. warning about an omitted enumeration code even if there is a
  1315. <code>default</code> label.
  1316. </p>
  1317. </dd>
  1318. <dt><code>-Wno-switch-bool</code></dt>
  1319. <dd><a name="index-Wswitch_002dbool"></a>
  1320. <a name="index-Wno_002dswitch_002dbool"></a>
  1321. <p>Do not warn when a <code>switch</code> statement has an index of boolean type
  1322. and the case values are outside the range of a boolean type.
  1323. It is possible to suppress this warning by casting the controlling
  1324. expression to a type other than <code>bool</code>. For example:
  1325. </p><div class="smallexample">
  1326. <pre class="smallexample">switch ((int) (a == 4))
  1327. {
  1328. &hellip;
  1329. }
  1330. </pre></div>
  1331. <p>This warning is enabled by default for C and C++ programs.
  1332. </p>
  1333. </dd>
  1334. <dt><code>-Wno-switch-outside-range</code></dt>
  1335. <dd><a name="index-Wswitch_002doutside_002drange"></a>
  1336. <a name="index-Wno_002dswitch_002doutside_002drange"></a>
  1337. <p>This option controls warnings when a <code>switch</code> case has a value
  1338. that is outside of its
  1339. respective type range. This warning is enabled by default for
  1340. C and C++ programs.
  1341. </p>
  1342. </dd>
  1343. <dt><code>-Wno-switch-unreachable</code></dt>
  1344. <dd><a name="index-Wswitch_002dunreachable"></a>
  1345. <a name="index-Wno_002dswitch_002dunreachable"></a>
  1346. <p>Do not warn when a <code>switch</code> statement contains statements between the
  1347. controlling expression and the first case label, which will never be
  1348. executed. For example:
  1349. </p><div class="smallexample">
  1350. <pre class="smallexample">switch (cond)
  1351. {
  1352. i = 15;
  1353. &hellip;
  1354. case 5:
  1355. &hellip;
  1356. }
  1357. </pre></div>
  1358. <p><samp>-Wswitch-unreachable</samp> does not warn if the statement between the
  1359. controlling expression and the first case label is just a declaration:
  1360. </p><div class="smallexample">
  1361. <pre class="smallexample">switch (cond)
  1362. {
  1363. int i;
  1364. &hellip;
  1365. case 5:
  1366. i = 5;
  1367. &hellip;
  1368. }
  1369. </pre></div>
  1370. <p>This warning is enabled by default for C and C++ programs.
  1371. </p>
  1372. </dd>
  1373. <dt><code>-Wsync-nand <span class="roman">(C and C++ only)</span></code></dt>
  1374. <dd><a name="index-Wsync_002dnand"></a>
  1375. <a name="index-Wno_002dsync_002dnand"></a>
  1376. <p>Warn when <code>__sync_fetch_and_nand</code> and <code>__sync_nand_and_fetch</code>
  1377. built-in functions are used. These functions changed semantics in GCC 4.4.
  1378. </p>
  1379. </dd>
  1380. <dt><code>-Wunused-but-set-parameter</code></dt>
  1381. <dd><a name="index-Wunused_002dbut_002dset_002dparameter"></a>
  1382. <a name="index-Wno_002dunused_002dbut_002dset_002dparameter"></a>
  1383. <p>Warn whenever a function parameter is assigned to, but otherwise unused
  1384. (aside from its declaration).
  1385. </p>
  1386. <p>To suppress this warning use the <code>unused</code> attribute
  1387. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1388. </p>
  1389. <p>This warning is also enabled by <samp>-Wunused</samp> together with
  1390. <samp>-Wextra</samp>.
  1391. </p>
  1392. </dd>
  1393. <dt><code>-Wunused-but-set-variable</code></dt>
  1394. <dd><a name="index-Wunused_002dbut_002dset_002dvariable"></a>
  1395. <a name="index-Wno_002dunused_002dbut_002dset_002dvariable"></a>
  1396. <p>Warn whenever a local variable is assigned to, but otherwise unused
  1397. (aside from its declaration).
  1398. This warning is enabled by <samp>-Wall</samp>.
  1399. </p>
  1400. <p>To suppress this warning use the <code>unused</code> attribute
  1401. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1402. </p>
  1403. <p>This warning is also enabled by <samp>-Wunused</samp>, which is enabled
  1404. by <samp>-Wall</samp>.
  1405. </p>
  1406. </dd>
  1407. <dt><code>-Wunused-function</code></dt>
  1408. <dd><a name="index-Wunused_002dfunction"></a>
  1409. <a name="index-Wno_002dunused_002dfunction"></a>
  1410. <p>Warn whenever a static function is declared but not defined or a
  1411. non-inline static function is unused.
  1412. This warning is enabled by <samp>-Wall</samp>.
  1413. </p>
  1414. </dd>
  1415. <dt><code>-Wunused-label</code></dt>
  1416. <dd><a name="index-Wunused_002dlabel"></a>
  1417. <a name="index-Wno_002dunused_002dlabel"></a>
  1418. <p>Warn whenever a label is declared but not used.
  1419. This warning is enabled by <samp>-Wall</samp>.
  1420. </p>
  1421. <p>To suppress this warning use the <code>unused</code> attribute
  1422. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1423. </p>
  1424. </dd>
  1425. <dt><code>-Wunused-local-typedefs <span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span></code></dt>
  1426. <dd><a name="index-Wunused_002dlocal_002dtypedefs"></a>
  1427. <a name="index-Wno_002dunused_002dlocal_002dtypedefs"></a>
  1428. <p>Warn when a typedef locally defined in a function is not used.
  1429. This warning is enabled by <samp>-Wall</samp>.
  1430. </p>
  1431. </dd>
  1432. <dt><code>-Wunused-parameter</code></dt>
  1433. <dd><a name="index-Wunused_002dparameter"></a>
  1434. <a name="index-Wno_002dunused_002dparameter"></a>
  1435. <p>Warn whenever a function parameter is unused aside from its declaration.
  1436. </p>
  1437. <p>To suppress this warning use the <code>unused</code> attribute
  1438. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1439. </p>
  1440. </dd>
  1441. <dt><code>-Wno-unused-result</code></dt>
  1442. <dd><a name="index-Wunused_002dresult"></a>
  1443. <a name="index-Wno_002dunused_002dresult"></a>
  1444. <p>Do not warn if a caller of a function marked with attribute
  1445. <code>warn_unused_result</code> (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>) does not use
  1446. its return value. The default is <samp>-Wunused-result</samp>.
  1447. </p>
  1448. </dd>
  1449. <dt><code>-Wunused-variable</code></dt>
  1450. <dd><a name="index-Wunused_002dvariable"></a>
  1451. <a name="index-Wno_002dunused_002dvariable"></a>
  1452. <p>Warn whenever a local or static variable is unused aside from its
  1453. declaration. This option implies <samp>-Wunused-const-variable=1</samp> for C,
  1454. but not for C++. This warning is enabled by <samp>-Wall</samp>.
  1455. </p>
  1456. <p>To suppress this warning use the <code>unused</code> attribute
  1457. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1458. </p>
  1459. </dd>
  1460. <dt><code>-Wunused-const-variable</code></dt>
  1461. <dt><code>-Wunused-const-variable=<var>n</var></code></dt>
  1462. <dd><a name="index-Wunused_002dconst_002dvariable"></a>
  1463. <a name="index-Wno_002dunused_002dconst_002dvariable"></a>
  1464. <p>Warn whenever a constant static variable is unused aside from its declaration.
  1465. <samp>-Wunused-const-variable=1</samp> is enabled by <samp>-Wunused-variable</samp>
  1466. for C, but not for C++. In C this declares variable storage, but in C++ this
  1467. is not an error since const variables take the place of <code>#define</code>s.
  1468. </p>
  1469. <p>To suppress this warning use the <code>unused</code> attribute
  1470. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1471. </p>
  1472. <dl compact="compact">
  1473. <dt><code>-Wunused-const-variable=1</code></dt>
  1474. <dd><p>This is the warning level that is enabled by <samp>-Wunused-variable</samp> for
  1475. C. It warns only about unused static const variables defined in the main
  1476. compilation unit, but not about static const variables declared in any
  1477. header included.
  1478. </p>
  1479. </dd>
  1480. <dt><code>-Wunused-const-variable=2</code></dt>
  1481. <dd><p>This warning level also warns for unused constant static variables in
  1482. headers (excluding system headers). This is the warning level of
  1483. <samp>-Wunused-const-variable</samp> and must be explicitly requested since
  1484. in C++ this isn&rsquo;t an error and in C it might be harder to clean up all
  1485. headers included.
  1486. </p></dd>
  1487. </dl>
  1488. </dd>
  1489. <dt><code>-Wunused-value</code></dt>
  1490. <dd><a name="index-Wunused_002dvalue"></a>
  1491. <a name="index-Wno_002dunused_002dvalue"></a>
  1492. <p>Warn whenever a statement computes a result that is explicitly not
  1493. used. To suppress this warning cast the unused expression to
  1494. <code>void</code>. This includes an expression-statement or the left-hand
  1495. side of a comma expression that contains no side effects. For example,
  1496. an expression such as <code>x[i,j]</code> causes a warning, while
  1497. <code>x[(void)i,j]</code> does not.
  1498. </p>
  1499. <p>This warning is enabled by <samp>-Wall</samp>.
  1500. </p>
  1501. </dd>
  1502. <dt><code>-Wunused</code></dt>
  1503. <dd><a name="index-Wunused"></a>
  1504. <a name="index-Wno_002dunused"></a>
  1505. <p>All the above <samp>-Wunused</samp> options combined.
  1506. </p>
  1507. <p>In order to get a warning about an unused function parameter, you must
  1508. either specify <samp>-Wextra -Wunused</samp> (note that <samp>-Wall</samp> implies
  1509. <samp>-Wunused</samp>), or separately specify <samp>-Wunused-parameter</samp>.
  1510. </p>
  1511. </dd>
  1512. <dt><code>-Wuninitialized</code></dt>
  1513. <dd><a name="index-Wuninitialized"></a>
  1514. <a name="index-Wno_002duninitialized"></a>
  1515. <p>Warn if an automatic variable is used without first being initialized.
  1516. In C++, warn if a non-static reference or non-static <code>const</code>
  1517. member appears in a class without constructors.
  1518. </p>
  1519. <p>If you want to warn about code that uses the uninitialized value of the
  1520. variable in its own initializer, use the <samp>-Winit-self</samp> option.
  1521. </p>
  1522. <p>These warnings occur for individual uninitialized elements of
  1523. structure, union or array variables as well as for variables that are
  1524. uninitialized as a whole. They do not occur for variables or elements
  1525. declared <code>volatile</code>. Because these warnings depend on
  1526. optimization, the exact variables or elements for which there are
  1527. warnings depend on the precise optimization options and version of GCC
  1528. used.
  1529. </p>
  1530. <p>Note that there may be no warning about a variable that is used only
  1531. to compute a value that itself is never used, because such
  1532. computations may be deleted by data flow analysis before the warnings
  1533. are printed.
  1534. </p>
  1535. </dd>
  1536. <dt><code>-Wno-invalid-memory-model</code></dt>
  1537. <dd><a name="index-Winvalid_002dmemory_002dmodel"></a>
  1538. <a name="index-Wno_002dinvalid_002dmemory_002dmodel"></a>
  1539. <p>This option controls warnings
  1540. for invocations of <a href="_005f_005fatomic-Builtins.html#g_t_005f_005fatomic-Builtins">__atomic Builtins</a>, <a href="_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins">__sync Builtins</a>,
  1541. and the C11 atomic generic functions with a memory consistency argument
  1542. that is either invalid for the operation or outside the range of values
  1543. of the <code>memory_order</code> enumeration. For example, since the
  1544. <code>__atomic_store</code> and <code>__atomic_store_n</code> built-ins are only
  1545. defined for the relaxed, release, and sequentially consistent memory
  1546. orders the following code is diagnosed:
  1547. </p>
  1548. <div class="smallexample">
  1549. <pre class="smallexample">void store (int *i)
  1550. {
  1551. __atomic_store_n (i, 0, memory_order_consume);
  1552. }
  1553. </pre></div>
  1554. <p><samp>-Winvalid-memory-model</samp> is enabled by default.
  1555. </p>
  1556. </dd>
  1557. <dt><code>-Wmaybe-uninitialized</code></dt>
  1558. <dd><a name="index-Wmaybe_002duninitialized"></a>
  1559. <a name="index-Wno_002dmaybe_002duninitialized"></a>
  1560. <p>For an automatic (i.e. local) variable, if there exists a path from the
  1561. function entry to a use of the variable that is initialized, but there exist
  1562. some other paths for which the variable is not initialized, the compiler
  1563. emits a warning if it cannot prove the uninitialized paths are not
  1564. executed at run time.
  1565. </p>
  1566. <p>These warnings are only possible in optimizing compilation, because otherwise
  1567. GCC does not keep track of the state of variables.
  1568. </p>
  1569. <p>These warnings are made optional because GCC may not be able to determine when
  1570. the code is correct in spite of appearing to have an error. Here is one
  1571. example of how this can happen:
  1572. </p>
  1573. <div class="smallexample">
  1574. <pre class="smallexample">{
  1575. int x;
  1576. switch (y)
  1577. {
  1578. case 1: x = 1;
  1579. break;
  1580. case 2: x = 4;
  1581. break;
  1582. case 3: x = 5;
  1583. }
  1584. foo (x);
  1585. }
  1586. </pre></div>
  1587. <p>If the value of <code>y</code> is always 1, 2 or 3, then <code>x</code> is
  1588. always initialized, but GCC doesn&rsquo;t know this. To suppress the
  1589. warning, you need to provide a default case with assert(0) or
  1590. similar code.
  1591. </p>
  1592. <a name="index-longjmp-warnings"></a>
  1593. <p>This option also warns when a non-volatile automatic variable might be
  1594. changed by a call to <code>longjmp</code>.
  1595. The compiler sees only the calls to <code>setjmp</code>. It cannot know
  1596. where <code>longjmp</code> will be called; in fact, a signal handler could
  1597. call it at any point in the code. As a result, you may get a warning
  1598. even when there is in fact no problem because <code>longjmp</code> cannot
  1599. in fact be called at the place that would cause a problem.
  1600. </p>
  1601. <p>Some spurious warnings can be avoided if you declare all the functions
  1602. you use that never return as <code>noreturn</code>. See <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
  1603. </p>
  1604. <p>This warning is enabled by <samp>-Wall</samp> or <samp>-Wextra</samp>.
  1605. </p>
  1606. </dd>
  1607. <dt><code>-Wunknown-pragmas</code></dt>
  1608. <dd><a name="index-Wunknown_002dpragmas"></a>
  1609. <a name="index-Wno_002dunknown_002dpragmas"></a>
  1610. <a name="index-warning-for-unknown-pragmas"></a>
  1611. <a name="index-unknown-pragmas_002c-warning"></a>
  1612. <a name="index-pragmas_002c-warning-of-unknown"></a>
  1613. <p>Warn when a <code>#pragma</code> directive is encountered that is not understood by
  1614. GCC. If this command-line option is used, warnings are even issued
  1615. for unknown pragmas in system header files. This is not the case if
  1616. the warnings are only enabled by the <samp>-Wall</samp> command-line option.
  1617. </p>
  1618. </dd>
  1619. <dt><code>-Wno-pragmas</code></dt>
  1620. <dd><a name="index-Wno_002dpragmas"></a>
  1621. <a name="index-Wpragmas"></a>
  1622. <p>Do not warn about misuses of pragmas, such as incorrect parameters,
  1623. invalid syntax, or conflicts between pragmas. See also
  1624. <samp>-Wunknown-pragmas</samp>.
  1625. </p>
  1626. </dd>
  1627. <dt><code>-Wno-prio-ctor-dtor</code></dt>
  1628. <dd><a name="index-Wno_002dprio_002dctor_002ddtor"></a>
  1629. <a name="index-Wprio_002dctor_002ddtor"></a>
  1630. <p>Do not warn if a priority from 0 to 100 is used for constructor or destructor.
  1631. The use of constructor and destructor attributes allow you to assign a
  1632. priority to the constructor/destructor to control its order of execution
  1633. before <code>main</code> is called or after it returns. The priority values must be
  1634. greater than 100 as the compiler reserves priority values between 0&ndash;100 for
  1635. the implementation.
  1636. </p>
  1637. </dd>
  1638. <dt><code>-Wstrict-aliasing</code></dt>
  1639. <dd><a name="index-Wstrict_002daliasing"></a>
  1640. <a name="index-Wno_002dstrict_002daliasing"></a>
  1641. <p>This option is only active when <samp>-fstrict-aliasing</samp> is active.
  1642. It warns about code that might break the strict aliasing rules that the
  1643. compiler is using for optimization. The warning does not catch all
  1644. cases, but does attempt to catch the more common pitfalls. It is
  1645. included in <samp>-Wall</samp>.
  1646. It is equivalent to <samp>-Wstrict-aliasing=3</samp>
  1647. </p>
  1648. </dd>
  1649. <dt><code>-Wstrict-aliasing=n</code></dt>
  1650. <dd><a name="index-Wstrict_002daliasing_003dn"></a>
  1651. <p>This option is only active when <samp>-fstrict-aliasing</samp> is active.
  1652. It warns about code that might break the strict aliasing rules that the
  1653. compiler is using for optimization.
  1654. Higher levels correspond to higher accuracy (fewer false positives).
  1655. Higher levels also correspond to more effort, similar to the way <samp>-O</samp>
  1656. works.
  1657. <samp>-Wstrict-aliasing</samp> is equivalent to <samp>-Wstrict-aliasing=3</samp>.
  1658. </p>
  1659. <p>Level 1: Most aggressive, quick, least accurate.
  1660. Possibly useful when higher levels
  1661. do not warn but <samp>-fstrict-aliasing</samp> still breaks the code, as it has very few
  1662. false negatives. However, it has many false positives.
  1663. Warns for all pointer conversions between possibly incompatible types,
  1664. even if never dereferenced. Runs in the front end only.
  1665. </p>
  1666. <p>Level 2: Aggressive, quick, not too precise.
  1667. May still have many false positives (not as many as level 1 though),
  1668. and few false negatives (but possibly more than level 1).
  1669. Unlike level 1, it only warns when an address is taken. Warns about
  1670. incomplete types. Runs in the front end only.
  1671. </p>
  1672. <p>Level 3 (default for <samp>-Wstrict-aliasing</samp>):
  1673. Should have very few false positives and few false
  1674. negatives. Slightly slower than levels 1 or 2 when optimization is enabled.
  1675. Takes care of the common pun+dereference pattern in the front end:
  1676. <code>*(int*)&amp;some_float</code>.
  1677. If optimization is enabled, it also runs in the back end, where it deals
  1678. with multiple statement cases using flow-sensitive points-to information.
  1679. Only warns when the converted pointer is dereferenced.
  1680. Does not warn about incomplete types.
  1681. </p>
  1682. </dd>
  1683. <dt><code>-Wstrict-overflow</code></dt>
  1684. <dt><code>-Wstrict-overflow=<var>n</var></code></dt>
  1685. <dd><a name="index-Wstrict_002doverflow"></a>
  1686. <a name="index-Wno_002dstrict_002doverflow"></a>
  1687. <p>This option is only active when signed overflow is undefined.
  1688. It warns about cases where the compiler optimizes based on the
  1689. assumption that signed overflow does not occur. Note that it does not
  1690. warn about all cases where the code might overflow: it only warns
  1691. about cases where the compiler implements some optimization. Thus
  1692. this warning depends on the optimization level.
  1693. </p>
  1694. <p>An optimization that assumes that signed overflow does not occur is
  1695. perfectly safe if the values of the variables involved are such that
  1696. overflow never does, in fact, occur. Therefore this warning can
  1697. easily give a false positive: a warning about code that is not
  1698. actually a problem. To help focus on important issues, several
  1699. warning levels are defined. No warnings are issued for the use of
  1700. undefined signed overflow when estimating how many iterations a loop
  1701. requires, in particular when determining whether a loop will be
  1702. executed at all.
  1703. </p>
  1704. <dl compact="compact">
  1705. <dt><code>-Wstrict-overflow=1</code></dt>
  1706. <dd><p>Warn about cases that are both questionable and easy to avoid. For
  1707. example the compiler simplifies
  1708. <code>x + 1 &gt; x</code> to <code>1</code>. This level of
  1709. <samp>-Wstrict-overflow</samp> is enabled by <samp>-Wall</samp>; higher levels
  1710. are not, and must be explicitly requested.
  1711. </p>
  1712. </dd>
  1713. <dt><code>-Wstrict-overflow=2</code></dt>
  1714. <dd><p>Also warn about other cases where a comparison is simplified to a
  1715. constant. For example: <code>abs (x) &gt;= 0</code>. This can only be
  1716. simplified when signed integer overflow is undefined, because
  1717. <code>abs (INT_MIN)</code> overflows to <code>INT_MIN</code>, which is less than
  1718. zero. <samp>-Wstrict-overflow</samp> (with no level) is the same as
  1719. <samp>-Wstrict-overflow=2</samp>.
  1720. </p>
  1721. </dd>
  1722. <dt><code>-Wstrict-overflow=3</code></dt>
  1723. <dd><p>Also warn about other cases where a comparison is simplified. For
  1724. example: <code>x + 1 &gt; 1</code> is simplified to <code>x &gt; 0</code>.
  1725. </p>
  1726. </dd>
  1727. <dt><code>-Wstrict-overflow=4</code></dt>
  1728. <dd><p>Also warn about other simplifications not covered by the above cases.
  1729. For example: <code>(x * 10) / 5</code> is simplified to <code>x * 2</code>.
  1730. </p>
  1731. </dd>
  1732. <dt><code>-Wstrict-overflow=5</code></dt>
  1733. <dd><p>Also warn about cases where the compiler reduces the magnitude of a
  1734. constant involved in a comparison. For example: <code>x + 2 &gt; y</code> is
  1735. simplified to <code>x + 1 &gt;= y</code>. This is reported only at the
  1736. highest warning level because this simplification applies to many
  1737. comparisons, so this warning level gives a very large number of
  1738. false positives.
  1739. </p></dd>
  1740. </dl>
  1741. </dd>
  1742. <dt><code>-Wstring-compare</code></dt>
  1743. <dd><a name="index-Wstring_002dcompare"></a>
  1744. <a name="index-Wno_002dstring_002dcompare"></a>
  1745. <p>Warn for calls to <code>strcmp</code> and <code>strncmp</code> whose result is
  1746. determined to be either zero or non-zero in tests for such equality
  1747. owing to the length of one argument being greater than the size of
  1748. the array the other argument is stored in (or the bound in the case
  1749. of <code>strncmp</code>). Such calls could be mistakes. For example,
  1750. the call to <code>strcmp</code> below is diagnosed because its result is
  1751. necessarily non-zero irrespective of the contents of the array <code>a</code>.
  1752. </p>
  1753. <div class="smallexample">
  1754. <pre class="smallexample">extern char a[4];
  1755. void f (char *d)
  1756. {
  1757. strcpy (d, &quot;string&quot;);
  1758. &hellip;
  1759. if (0 == strcmp (a, d)) // cannot be true
  1760. puts (&quot;a and d are the same&quot;);
  1761. }
  1762. </pre></div>
  1763. <p><samp>-Wstring-compare</samp> is enabled by <samp>-Wextra</samp>.
  1764. </p>
  1765. </dd>
  1766. <dt><code>-Wstringop-overflow</code></dt>
  1767. <dt><code>-Wstringop-overflow=<var>type</var></code></dt>
  1768. <dd><a name="index-Wstringop_002doverflow"></a>
  1769. <a name="index-Wno_002dstringop_002doverflow"></a>
  1770. <p>Warn for calls to string manipulation functions such as <code>memcpy</code> and
  1771. <code>strcpy</code> that are determined to overflow the destination buffer. The
  1772. optional argument is one greater than the type of Object Size Checking to
  1773. perform to determine the size of the destination. See <a href="Object-Size-Checking.html#Object-Size-Checking">Object Size Checking</a>.
  1774. The argument is meaningful only for functions that operate on character arrays
  1775. but not for raw memory functions like <code>memcpy</code> which always make use
  1776. of Object Size type-0. The option also warns for calls that specify a size
  1777. in excess of the largest possible object or at most <code>SIZE_MAX / 2</code> bytes.
  1778. The option produces the best results with optimization enabled but can detect
  1779. a small subset of simple buffer overflows even without optimization in
  1780. calls to the GCC built-in functions like <code>__builtin_memcpy</code> that
  1781. correspond to the standard functions. In any case, the option warns about
  1782. just a subset of buffer overflows detected by the corresponding overflow
  1783. checking built-ins. For example, the option issues a warning for
  1784. the <code>strcpy</code> call below because it copies at least 5 characters
  1785. (the string <code>&quot;blue&quot;</code> including the terminating NUL) into the buffer
  1786. of size 4.
  1787. </p>
  1788. <div class="smallexample">
  1789. <pre class="smallexample">enum Color { blue, purple, yellow };
  1790. const char* f (enum Color clr)
  1791. {
  1792. static char buf [4];
  1793. const char *str;
  1794. switch (clr)
  1795. {
  1796. case blue: str = &quot;blue&quot;; break;
  1797. case purple: str = &quot;purple&quot;; break;
  1798. case yellow: str = &quot;yellow&quot;; break;
  1799. }
  1800. return strcpy (buf, str); // warning here
  1801. }
  1802. </pre></div>
  1803. <p>Option <samp>-Wstringop-overflow=2</samp> is enabled by default.
  1804. </p>
  1805. <dl compact="compact">
  1806. <dt><code>-Wstringop-overflow</code></dt>
  1807. <dt><code>-Wstringop-overflow=1</code></dt>
  1808. <dd><a name="index-Wstringop_002doverflow-1"></a>
  1809. <a name="index-Wno_002dstringop_002doverflow-1"></a>
  1810. <p>The <samp>-Wstringop-overflow=1</samp> option uses type-zero Object Size Checking
  1811. to determine the sizes of destination objects. This is the default setting
  1812. of the option. At this setting the option does not warn for writes past
  1813. the end of subobjects of larger objects accessed by pointers unless the
  1814. size of the largest surrounding object is known. When the destination may
  1815. be one of several objects it is assumed to be the largest one of them. On
  1816. Linux systems, when optimization is enabled at this setting the option warns
  1817. for the same code as when the <code>_FORTIFY_SOURCE</code> macro is defined to
  1818. a non-zero value.
  1819. </p>
  1820. </dd>
  1821. <dt><code>-Wstringop-overflow=2</code></dt>
  1822. <dd><p>The <samp>-Wstringop-overflow=2</samp> option uses type-one Object Size Checking
  1823. to determine the sizes of destination objects. At this setting the option
  1824. warna about overflows when writing to members of the largest complete
  1825. objects whose exact size is known. However, it does not warn for excessive
  1826. writes to the same members of unknown objects referenced by pointers since
  1827. they may point to arrays containing unknown numbers of elements.
  1828. </p>
  1829. </dd>
  1830. <dt><code>-Wstringop-overflow=3</code></dt>
  1831. <dd><p>The <samp>-Wstringop-overflow=3</samp> option uses type-two Object Size Checking
  1832. to determine the sizes of destination objects. At this setting the option
  1833. warns about overflowing the smallest object or data member. This is the
  1834. most restrictive setting of the option that may result in warnings for safe
  1835. code.
  1836. </p>
  1837. </dd>
  1838. <dt><code>-Wstringop-overflow=4</code></dt>
  1839. <dd><p>The <samp>-Wstringop-overflow=4</samp> option uses type-three Object Size Checking
  1840. to determine the sizes of destination objects. At this setting the option
  1841. warns about overflowing any data members, and when the destination is
  1842. one of several objects it uses the size of the largest of them to decide
  1843. whether to issue a warning. Similarly to <samp>-Wstringop-overflow=3</samp> this
  1844. setting of the option may result in warnings for benign code.
  1845. </p></dd>
  1846. </dl>
  1847. </dd>
  1848. <dt><code>-Wno-stringop-truncation</code></dt>
  1849. <dd><a name="index-Wstringop_002dtruncation"></a>
  1850. <a name="index-Wno_002dstringop_002dtruncation"></a>
  1851. <p>Do not warn for calls to bounded string manipulation functions
  1852. such as <code>strncat</code>,
  1853. <code>strncpy</code>, and <code>stpncpy</code> that may either truncate the copied string
  1854. or leave the destination unchanged.
  1855. </p>
  1856. <p>In the following example, the call to <code>strncat</code> specifies a bound that
  1857. is less than the length of the source string. As a result, the copy of
  1858. the source will be truncated and so the call is diagnosed. To avoid the
  1859. warning use <code>bufsize - strlen (buf) - 1)</code> as the bound.
  1860. </p>
  1861. <div class="smallexample">
  1862. <pre class="smallexample">void append (char *buf, size_t bufsize)
  1863. {
  1864. strncat (buf, &quot;.txt&quot;, 3);
  1865. }
  1866. </pre></div>
  1867. <p>As another example, the following call to <code>strncpy</code> results in copying
  1868. to <code>d</code> just the characters preceding the terminating NUL, without
  1869. appending the NUL to the end. Assuming the result of <code>strncpy</code> is
  1870. necessarily a NUL-terminated string is a common mistake, and so the call
  1871. is diagnosed. To avoid the warning when the result is not expected to be
  1872. NUL-terminated, call <code>memcpy</code> instead.
  1873. </p>
  1874. <div class="smallexample">
  1875. <pre class="smallexample">void copy (char *d, const char *s)
  1876. {
  1877. strncpy (d, s, strlen (s));
  1878. }
  1879. </pre></div>
  1880. <p>In the following example, the call to <code>strncpy</code> specifies the size
  1881. of the destination buffer as the bound. If the length of the source
  1882. string is equal to or greater than this size the result of the copy will
  1883. not be NUL-terminated. Therefore, the call is also diagnosed. To avoid
  1884. the warning, specify <code>sizeof buf - 1</code> as the bound and set the last
  1885. element of the buffer to <code>NUL</code>.
  1886. </p>
  1887. <div class="smallexample">
  1888. <pre class="smallexample">void copy (const char *s)
  1889. {
  1890. char buf[80];
  1891. strncpy (buf, s, sizeof buf);
  1892. &hellip;
  1893. }
  1894. </pre></div>
  1895. <p>In situations where a character array is intended to store a sequence
  1896. of bytes with no terminating <code>NUL</code> such an array may be annotated
  1897. with attribute <code>nonstring</code> to avoid this warning. Such arrays,
  1898. however, are not suitable arguments to functions that expect
  1899. <code>NUL</code>-terminated strings. To help detect accidental misuses of
  1900. such arrays GCC issues warnings unless it can prove that the use is
  1901. safe. See <a href="Common-Variable-Attributes.html#Common-Variable-Attributes">Common Variable Attributes</a>.
  1902. </p>
  1903. </dd>
  1904. <dt><code>-Wsuggest-attribute=<span class="roman">[</span>pure<span class="roman">|</span>const<span class="roman">|</span>noreturn<span class="roman">|</span>format<span class="roman">|</span>cold<span class="roman">|</span>malloc<span class="roman">]</span></code></dt>
  1905. <dd><a name="index-Wsuggest_002dattribute_003d"></a>
  1906. <a name="index-Wno_002dsuggest_002dattribute_003d"></a>
  1907. <p>Warn for cases where adding an attribute may be beneficial. The
  1908. attributes currently supported are listed below.
  1909. </p>
  1910. <dl compact="compact">
  1911. <dt><code>-Wsuggest-attribute=pure</code></dt>
  1912. <dt><code>-Wsuggest-attribute=const</code></dt>
  1913. <dt><code>-Wsuggest-attribute=noreturn</code></dt>
  1914. <dt><code>-Wmissing-noreturn</code></dt>
  1915. <dt><code>-Wsuggest-attribute=malloc</code></dt>
  1916. <dd><a name="index-Wsuggest_002dattribute_003dpure"></a>
  1917. <a name="index-Wno_002dsuggest_002dattribute_003dpure"></a>
  1918. <a name="index-Wsuggest_002dattribute_003dconst"></a>
  1919. <a name="index-Wno_002dsuggest_002dattribute_003dconst"></a>
  1920. <a name="index-Wsuggest_002dattribute_003dnoreturn"></a>
  1921. <a name="index-Wno_002dsuggest_002dattribute_003dnoreturn"></a>
  1922. <a name="index-Wmissing_002dnoreturn"></a>
  1923. <a name="index-Wno_002dmissing_002dnoreturn"></a>
  1924. <a name="index-Wsuggest_002dattribute_003dmalloc"></a>
  1925. <a name="index-Wno_002dsuggest_002dattribute_003dmalloc"></a>
  1926. <p>Warn about functions that might be candidates for attributes
  1927. <code>pure</code>, <code>const</code> or <code>noreturn</code> or <code>malloc</code>. The compiler
  1928. only warns for functions visible in other compilation units or (in the case of
  1929. <code>pure</code> and <code>const</code>) if it cannot prove that the function returns
  1930. normally. A function returns normally if it doesn&rsquo;t contain an infinite loop or
  1931. return abnormally by throwing, calling <code>abort</code> or trapping. This analysis
  1932. requires option <samp>-fipa-pure-const</samp>, which is enabled by default at
  1933. <samp>-O</samp> and higher. Higher optimization levels improve the accuracy
  1934. of the analysis.
  1935. </p>
  1936. </dd>
  1937. <dt><code>-Wsuggest-attribute=format</code></dt>
  1938. <dt><code>-Wmissing-format-attribute</code></dt>
  1939. <dd><a name="index-Wsuggest_002dattribute_003dformat"></a>
  1940. <a name="index-Wmissing_002dformat_002dattribute"></a>
  1941. <a name="index-Wno_002dsuggest_002dattribute_003dformat"></a>
  1942. <a name="index-Wno_002dmissing_002dformat_002dattribute"></a>
  1943. <a name="index-Wformat-2"></a>
  1944. <a name="index-Wno_002dformat-1"></a>
  1945. <p>Warn about function pointers that might be candidates for <code>format</code>
  1946. attributes. Note these are only possible candidates, not absolute ones.
  1947. GCC guesses that function pointers with <code>format</code> attributes that
  1948. are used in assignment, initialization, parameter passing or return
  1949. statements should have a corresponding <code>format</code> attribute in the
  1950. resulting type. I.e. the left-hand side of the assignment or
  1951. initialization, the type of the parameter variable, or the return type
  1952. of the containing function respectively should also have a <code>format</code>
  1953. attribute to avoid the warning.
  1954. </p>
  1955. <p>GCC also warns about function definitions that might be
  1956. candidates for <code>format</code> attributes. Again, these are only
  1957. possible candidates. GCC guesses that <code>format</code> attributes
  1958. might be appropriate for any function that calls a function like
  1959. <code>vprintf</code> or <code>vscanf</code>, but this might not always be the
  1960. case, and some functions for which <code>format</code> attributes are
  1961. appropriate may not be detected.
  1962. </p>
  1963. </dd>
  1964. <dt><code>-Wsuggest-attribute=cold</code></dt>
  1965. <dd><a name="index-Wsuggest_002dattribute_003dcold"></a>
  1966. <a name="index-Wno_002dsuggest_002dattribute_003dcold"></a>
  1967. <p>Warn about functions that might be candidates for <code>cold</code> attribute. This
  1968. is based on static detection and generally only warns about functions which
  1969. always leads to a call to another <code>cold</code> function such as wrappers of
  1970. C++ <code>throw</code> or fatal error reporting functions leading to <code>abort</code>.
  1971. </p></dd>
  1972. </dl>
  1973. </dd>
  1974. <dt><code>-Walloc-zero</code></dt>
  1975. <dd><a name="index-Wno_002dalloc_002dzero"></a>
  1976. <a name="index-Walloc_002dzero"></a>
  1977. <p>Warn about calls to allocation functions decorated with attribute
  1978. <code>alloc_size</code> that specify zero bytes, including those to the built-in
  1979. forms of the functions <code>aligned_alloc</code>, <code>alloca</code>, <code>calloc</code>,
  1980. <code>malloc</code>, and <code>realloc</code>. Because the behavior of these functions
  1981. when called with a zero size differs among implementations (and in the case
  1982. of <code>realloc</code> has been deprecated) relying on it may result in subtle
  1983. portability bugs and should be avoided.
  1984. </p>
  1985. </dd>
  1986. <dt><code>-Walloc-size-larger-than=<var>byte-size</var></code></dt>
  1987. <dd><a name="index-Walloc_002dsize_002dlarger_002dthan_003d"></a>
  1988. <a name="index-Wno_002dalloc_002dsize_002dlarger_002dthan"></a>
  1989. <p>Warn about calls to functions decorated with attribute <code>alloc_size</code>
  1990. that attempt to allocate objects larger than the specified number of bytes,
  1991. or where the result of the size computation in an integer type with infinite
  1992. precision would exceed the value of &lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; on the target.
  1993. <samp>-Walloc-size-larger-than=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default.
  1994. Warnings controlled by the option can be disabled either by specifying
  1995. <var>byte-size</var> of &lsquo;<samp>SIZE_MAX</samp>&rsquo; or more or by
  1996. <samp>-Wno-alloc-size-larger-than</samp>.
  1997. See <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
  1998. </p>
  1999. </dd>
  2000. <dt><code>-Wno-alloc-size-larger-than</code></dt>
  2001. <dd><a name="index-Wno_002dalloc_002dsize_002dlarger_002dthan-1"></a>
  2002. <p>Disable <samp>-Walloc-size-larger-than=</samp> warnings. The option is
  2003. equivalent to <samp>-Walloc-size-larger-than=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or
  2004. larger.
  2005. </p>
  2006. </dd>
  2007. <dt><code>-Walloca</code></dt>
  2008. <dd><a name="index-Wno_002dalloca"></a>
  2009. <a name="index-Walloca"></a>
  2010. <p>This option warns on all uses of <code>alloca</code> in the source.
  2011. </p>
  2012. </dd>
  2013. <dt><code>-Walloca-larger-than=<var>byte-size</var></code></dt>
  2014. <dd><a name="index-Walloca_002dlarger_002dthan_003d"></a>
  2015. <a name="index-Wno_002dalloca_002dlarger_002dthan"></a>
  2016. <p>This option warns on calls to <code>alloca</code> with an integer argument whose
  2017. value is either zero, or that is not bounded by a controlling predicate
  2018. that limits its value to at most <var>byte-size</var>. It also warns for calls
  2019. to <code>alloca</code> where the bound value is unknown. Arguments of non-integer
  2020. types are considered unbounded even if they appear to be constrained to
  2021. the expected range.
  2022. </p>
  2023. <p>For example, a bounded case of <code>alloca</code> could be:
  2024. </p>
  2025. <div class="smallexample">
  2026. <pre class="smallexample">void func (size_t n)
  2027. {
  2028. void *p;
  2029. if (n &lt;= 1000)
  2030. p = alloca (n);
  2031. else
  2032. p = malloc (n);
  2033. f (p);
  2034. }
  2035. </pre></div>
  2036. <p>In the above example, passing <code>-Walloca-larger-than=1000</code> would not
  2037. issue a warning because the call to <code>alloca</code> is known to be at most
  2038. 1000 bytes. However, if <code>-Walloca-larger-than=500</code> were passed,
  2039. the compiler would emit a warning.
  2040. </p>
  2041. <p>Unbounded uses, on the other hand, are uses of <code>alloca</code> with no
  2042. controlling predicate constraining its integer argument. For example:
  2043. </p>
  2044. <div class="smallexample">
  2045. <pre class="smallexample">void func ()
  2046. {
  2047. void *p = alloca (n);
  2048. f (p);
  2049. }
  2050. </pre></div>
  2051. <p>If <code>-Walloca-larger-than=500</code> were passed, the above would trigger
  2052. a warning, but this time because of the lack of bounds checking.
  2053. </p>
  2054. <p>Note, that even seemingly correct code involving signed integers could
  2055. cause a warning:
  2056. </p>
  2057. <div class="smallexample">
  2058. <pre class="smallexample">void func (signed int n)
  2059. {
  2060. if (n &lt; 500)
  2061. {
  2062. p = alloca (n);
  2063. f (p);
  2064. }
  2065. }
  2066. </pre></div>
  2067. <p>In the above example, <var>n</var> could be negative, causing a larger than
  2068. expected argument to be implicitly cast into the <code>alloca</code> call.
  2069. </p>
  2070. <p>This option also warns when <code>alloca</code> is used in a loop.
  2071. </p>
  2072. <p><samp>-Walloca-larger-than=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default
  2073. but is usually only effective when <samp>-ftree-vrp</samp> is active (default
  2074. for <samp>-O2</samp> and above).
  2075. </p>
  2076. <p>See also <samp>-Wvla-larger-than=</samp>&lsquo;<samp>byte-size</samp>&rsquo;.
  2077. </p>
  2078. </dd>
  2079. <dt><code>-Wno-alloca-larger-than</code></dt>
  2080. <dd><a name="index-Wno_002dalloca_002dlarger_002dthan-1"></a>
  2081. <p>Disable <samp>-Walloca-larger-than=</samp> warnings. The option is
  2082. equivalent to <samp>-Walloca-larger-than=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or larger.
  2083. </p>
  2084. </dd>
  2085. <dt><code>-Warith-conversion</code></dt>
  2086. <dd><a name="index-Warith_002dconversion"></a>
  2087. <a name="index-Wno_002darith_002dconversion"></a>
  2088. <p>Do warn about implicit conversions from arithmetic operations even
  2089. when conversion of the operands to the same type cannot change their
  2090. values. This affects warnings from <samp>-Wconversion</samp>,
  2091. <samp>-Wfloat-conversion</samp>, and <samp>-Wsign-conversion</samp>.
  2092. </p>
  2093. <div class="smallexample">
  2094. <pre class="smallexample">void f (char c, int i)
  2095. {
  2096. c = c + i; // warns with <samp>-Wconversion</samp>
  2097. c = c + 1; // only warns with <samp>-Warith-conversion</samp>
  2098. }
  2099. </pre></div>
  2100. </dd>
  2101. <dt><code>-Warray-bounds</code></dt>
  2102. <dt><code>-Warray-bounds=<var>n</var></code></dt>
  2103. <dd><a name="index-Wno_002darray_002dbounds"></a>
  2104. <a name="index-Warray_002dbounds"></a>
  2105. <p>This option is only active when <samp>-ftree-vrp</samp> is active
  2106. (default for <samp>-O2</samp> and above). It warns about subscripts to arrays
  2107. that are always out of bounds. This warning is enabled by <samp>-Wall</samp>.
  2108. </p>
  2109. <dl compact="compact">
  2110. <dt><code>-Warray-bounds=1</code></dt>
  2111. <dd><p>This is the warning level of <samp>-Warray-bounds</samp> and is enabled
  2112. by <samp>-Wall</samp>; higher levels are not, and must be explicitly requested.
  2113. </p>
  2114. </dd>
  2115. <dt><code>-Warray-bounds=2</code></dt>
  2116. <dd><p>This warning level also warns about out of bounds access for
  2117. arrays at the end of a struct and for arrays accessed through
  2118. pointers. This warning level may give a larger number of
  2119. false positives and is deactivated by default.
  2120. </p></dd>
  2121. </dl>
  2122. </dd>
  2123. <dt><code>-Wattribute-alias=<var>n</var></code></dt>
  2124. <dt><code>-Wno-attribute-alias</code></dt>
  2125. <dd><a name="index-Wattribute_002dalias"></a>
  2126. <a name="index-Wno_002dattribute_002dalias"></a>
  2127. <p>Warn about declarations using the <code>alias</code> and similar attributes whose
  2128. target is incompatible with the type of the alias.
  2129. See <a href="Function-Attributes.html#Function-Attributes">Declaring Attributes of Functions</a>.
  2130. </p>
  2131. <dl compact="compact">
  2132. <dt><code>-Wattribute-alias=1</code></dt>
  2133. <dd><p>The default warning level of the <samp>-Wattribute-alias</samp> option diagnoses
  2134. incompatibilities between the type of the alias declaration and that of its
  2135. target. Such incompatibilities are typically indicative of bugs.
  2136. </p>
  2137. </dd>
  2138. <dt><code>-Wattribute-alias=2</code></dt>
  2139. <dd>
  2140. <p>At this level <samp>-Wattribute-alias</samp> also diagnoses cases where
  2141. the attributes of the alias declaration are more restrictive than the
  2142. attributes applied to its target. These mismatches can potentially
  2143. result in incorrect code generation. In other cases they may be
  2144. benign and could be resolved simply by adding the missing attribute to
  2145. the target. For comparison, see the <samp>-Wmissing-attributes</samp>
  2146. option, which controls diagnostics when the alias declaration is less
  2147. restrictive than the target, rather than more restrictive.
  2148. </p>
  2149. <p>Attributes considered include <code>alloc_align</code>, <code>alloc_size</code>,
  2150. <code>cold</code>, <code>const</code>, <code>hot</code>, <code>leaf</code>, <code>malloc</code>,
  2151. <code>nonnull</code>, <code>noreturn</code>, <code>nothrow</code>, <code>pure</code>,
  2152. <code>returns_nonnull</code>, and <code>returns_twice</code>.
  2153. </p></dd>
  2154. </dl>
  2155. <p><samp>-Wattribute-alias</samp> is equivalent to <samp>-Wattribute-alias=1</samp>.
  2156. This is the default. You can disable these warnings with either
  2157. <samp>-Wno-attribute-alias</samp> or <samp>-Wattribute-alias=0</samp>.
  2158. </p>
  2159. </dd>
  2160. <dt><code>-Wbool-compare</code></dt>
  2161. <dd><a name="index-Wno_002dbool_002dcompare"></a>
  2162. <a name="index-Wbool_002dcompare"></a>
  2163. <p>Warn about boolean expression compared with an integer value different from
  2164. <code>true</code>/<code>false</code>. For instance, the following comparison is
  2165. always false:
  2166. </p><div class="smallexample">
  2167. <pre class="smallexample">int n = 5;
  2168. &hellip;
  2169. if ((n &gt; 1) == 2) { &hellip; }
  2170. </pre></div>
  2171. <p>This warning is enabled by <samp>-Wall</samp>.
  2172. </p>
  2173. </dd>
  2174. <dt><code>-Wbool-operation</code></dt>
  2175. <dd><a name="index-Wno_002dbool_002doperation"></a>
  2176. <a name="index-Wbool_002doperation"></a>
  2177. <p>Warn about suspicious operations on expressions of a boolean type. For
  2178. instance, bitwise negation of a boolean is very likely a bug in the program.
  2179. For C, this warning also warns about incrementing or decrementing a boolean,
  2180. which rarely makes sense. (In C++, decrementing a boolean is always invalid.
  2181. Incrementing a boolean is invalid in C++17, and deprecated otherwise.)
  2182. </p>
  2183. <p>This warning is enabled by <samp>-Wall</samp>.
  2184. </p>
  2185. </dd>
  2186. <dt><code>-Wduplicated-branches</code></dt>
  2187. <dd><a name="index-Wno_002dduplicated_002dbranches"></a>
  2188. <a name="index-Wduplicated_002dbranches"></a>
  2189. <p>Warn when an if-else has identical branches. This warning detects cases like
  2190. </p><div class="smallexample">
  2191. <pre class="smallexample">if (p != NULL)
  2192. return 0;
  2193. else
  2194. return 0;
  2195. </pre></div>
  2196. <p>It doesn&rsquo;t warn when both branches contain just a null statement. This warning
  2197. also warn for conditional operators:
  2198. </p><div class="smallexample">
  2199. <pre class="smallexample"> int i = x ? *p : *p;
  2200. </pre></div>
  2201. </dd>
  2202. <dt><code>-Wduplicated-cond</code></dt>
  2203. <dd><a name="index-Wno_002dduplicated_002dcond"></a>
  2204. <a name="index-Wduplicated_002dcond"></a>
  2205. <p>Warn about duplicated conditions in an if-else-if chain. For instance,
  2206. warn for the following code:
  2207. </p><div class="smallexample">
  2208. <pre class="smallexample">if (p-&gt;q != NULL) { &hellip; }
  2209. else if (p-&gt;q != NULL) { &hellip; }
  2210. </pre></div>
  2211. </dd>
  2212. <dt><code>-Wframe-address</code></dt>
  2213. <dd><a name="index-Wno_002dframe_002daddress"></a>
  2214. <a name="index-Wframe_002daddress"></a>
  2215. <p>Warn when the &lsquo;<samp>__builtin_frame_address</samp>&rsquo; or &lsquo;<samp>__builtin_return_address</samp>&rsquo;
  2216. is called with an argument greater than 0. Such calls may return indeterminate
  2217. values or crash the program. The warning is included in <samp>-Wall</samp>.
  2218. </p>
  2219. </dd>
  2220. <dt><code>-Wno-discarded-qualifiers <span class="roman">(C and Objective-C only)</span></code></dt>
  2221. <dd><a name="index-Wno_002ddiscarded_002dqualifiers"></a>
  2222. <a name="index-Wdiscarded_002dqualifiers"></a>
  2223. <p>Do not warn if type qualifiers on pointers are being discarded.
  2224. Typically, the compiler warns if a <code>const char *</code> variable is
  2225. passed to a function that takes a <code>char *</code> parameter. This option
  2226. can be used to suppress such a warning.
  2227. </p>
  2228. </dd>
  2229. <dt><code>-Wno-discarded-array-qualifiers <span class="roman">(C and Objective-C only)</span></code></dt>
  2230. <dd><a name="index-Wno_002ddiscarded_002darray_002dqualifiers"></a>
  2231. <a name="index-Wdiscarded_002darray_002dqualifiers"></a>
  2232. <p>Do not warn if type qualifiers on arrays which are pointer targets
  2233. are being discarded. Typically, the compiler warns if a
  2234. <code>const int (*)[]</code> variable is passed to a function that
  2235. takes a <code>int (*)[]</code> parameter. This option can be used to
  2236. suppress such a warning.
  2237. </p>
  2238. </dd>
  2239. <dt><code>-Wno-incompatible-pointer-types <span class="roman">(C and Objective-C only)</span></code></dt>
  2240. <dd><a name="index-Wno_002dincompatible_002dpointer_002dtypes"></a>
  2241. <a name="index-Wincompatible_002dpointer_002dtypes"></a>
  2242. <p>Do not warn when there is a conversion between pointers that have incompatible
  2243. types. This warning is for cases not covered by <samp>-Wno-pointer-sign</samp>,
  2244. which warns for pointer argument passing or assignment with different
  2245. signedness.
  2246. </p>
  2247. </dd>
  2248. <dt><code>-Wno-int-conversion <span class="roman">(C and Objective-C only)</span></code></dt>
  2249. <dd><a name="index-Wno_002dint_002dconversion"></a>
  2250. <a name="index-Wint_002dconversion"></a>
  2251. <p>Do not warn about incompatible integer to pointer and pointer to integer
  2252. conversions. This warning is about implicit conversions; for explicit
  2253. conversions the warnings <samp>-Wno-int-to-pointer-cast</samp> and
  2254. <samp>-Wno-pointer-to-int-cast</samp> may be used.
  2255. </p>
  2256. </dd>
  2257. <dt><code>-Wzero-length-bounds</code></dt>
  2258. <dd><a name="index-Wzero_002dlength_002dbounds"></a>
  2259. <a name="index-Wzero_002dlength_002dbounds-1"></a>
  2260. <p>Warn about accesses to elements of zero-length array members that might
  2261. overlap other members of the same object. Declaring interior zero-length
  2262. arrays is discouraged because accesses to them are undefined. See
  2263. See <a href="Zero-Length.html#Zero-Length">Zero Length</a>.
  2264. </p>
  2265. <p>For example, the first two stores in function <code>bad</code> are diagnosed
  2266. because the array elements overlap the subsequent members <code>b</code> and
  2267. <code>c</code>. The third store is diagnosed by <samp>-Warray-bounds</samp>
  2268. because it is beyond the bounds of the enclosing object.
  2269. </p>
  2270. <div class="smallexample">
  2271. <pre class="smallexample">struct X { int a[0]; int b, c; };
  2272. struct X x;
  2273. void bad (void)
  2274. {
  2275. x.a[0] = 0; // -Wzero-length-bounds
  2276. x.a[1] = 1; // -Wzero-length-bounds
  2277. x.a[2] = 2; // -Warray-bounds
  2278. }
  2279. </pre></div>
  2280. <p>Option <samp>-Wzero-length-bounds</samp> is enabled by <samp>-Warray-bounds</samp>.
  2281. </p>
  2282. </dd>
  2283. <dt><code>-Wno-div-by-zero</code></dt>
  2284. <dd><a name="index-Wno_002ddiv_002dby_002dzero"></a>
  2285. <a name="index-Wdiv_002dby_002dzero"></a>
  2286. <p>Do not warn about compile-time integer division by zero. Floating-point
  2287. division by zero is not warned about, as it can be a legitimate way of
  2288. obtaining infinities and NaNs.
  2289. </p>
  2290. </dd>
  2291. <dt><code>-Wsystem-headers</code></dt>
  2292. <dd><a name="index-Wsystem_002dheaders"></a>
  2293. <a name="index-Wno_002dsystem_002dheaders"></a>
  2294. <a name="index-warnings-from-system-headers"></a>
  2295. <a name="index-system-headers_002c-warnings-from"></a>
  2296. <p>Print warning messages for constructs found in system header files.
  2297. Warnings from system headers are normally suppressed, on the assumption
  2298. that they usually do not indicate real problems and would only make the
  2299. compiler output harder to read. Using this command-line option tells
  2300. GCC to emit warnings from system headers as if they occurred in user
  2301. code. However, note that using <samp>-Wall</samp> in conjunction with this
  2302. option does <em>not</em> warn about unknown pragmas in system
  2303. headers&mdash;for that, <samp>-Wunknown-pragmas</samp> must also be used.
  2304. </p>
  2305. </dd>
  2306. <dt><code>-Wtautological-compare</code></dt>
  2307. <dd><a name="index-Wtautological_002dcompare"></a>
  2308. <a name="index-Wno_002dtautological_002dcompare"></a>
  2309. <p>Warn if a self-comparison always evaluates to true or false. This
  2310. warning detects various mistakes such as:
  2311. </p><div class="smallexample">
  2312. <pre class="smallexample">int i = 1;
  2313. &hellip;
  2314. if (i &gt; i) { &hellip; }
  2315. </pre></div>
  2316. <p>This warning also warns about bitwise comparisons that always evaluate
  2317. to true or false, for instance:
  2318. </p><div class="smallexample">
  2319. <pre class="smallexample">if ((a &amp; 16) == 10) { &hellip; }
  2320. </pre></div>
  2321. <p>will always be false.
  2322. </p>
  2323. <p>This warning is enabled by <samp>-Wall</samp>.
  2324. </p>
  2325. </dd>
  2326. <dt><code>-Wtrampolines</code></dt>
  2327. <dd><a name="index-Wtrampolines"></a>
  2328. <a name="index-Wno_002dtrampolines"></a>
  2329. <p>Warn about trampolines generated for pointers to nested functions.
  2330. A trampoline is a small piece of data or code that is created at run
  2331. time on the stack when the address of a nested function is taken, and is
  2332. used to call the nested function indirectly. For some targets, it is
  2333. made up of data only and thus requires no special treatment. But, for
  2334. most targets, it is made up of code and thus requires the stack to be
  2335. made executable in order for the program to work properly.
  2336. </p>
  2337. </dd>
  2338. <dt><code>-Wfloat-equal</code></dt>
  2339. <dd><a name="index-Wfloat_002dequal"></a>
  2340. <a name="index-Wno_002dfloat_002dequal"></a>
  2341. <p>Warn if floating-point values are used in equality comparisons.
  2342. </p>
  2343. <p>The idea behind this is that sometimes it is convenient (for the
  2344. programmer) to consider floating-point values as approximations to
  2345. infinitely precise real numbers. If you are doing this, then you need
  2346. to compute (by analyzing the code, or in some other way) the maximum or
  2347. likely maximum error that the computation introduces, and allow for it
  2348. when performing comparisons (and when producing output, but that&rsquo;s a
  2349. different problem). In particular, instead of testing for equality, you
  2350. should check to see whether the two values have ranges that overlap; and
  2351. this is done with the relational operators, so equality comparisons are
  2352. probably mistaken.
  2353. </p>
  2354. </dd>
  2355. <dt><code>-Wtraditional <span class="roman">(C and Objective-C only)</span></code></dt>
  2356. <dd><a name="index-Wtraditional"></a>
  2357. <a name="index-Wno_002dtraditional"></a>
  2358. <p>Warn about certain constructs that behave differently in traditional and
  2359. ISO C. Also warn about ISO C constructs that have no traditional C
  2360. equivalent, and/or problematic constructs that should be avoided.
  2361. </p>
  2362. <ul>
  2363. <li> Macro parameters that appear within string literals in the macro body.
  2364. In traditional C macro replacement takes place within string literals,
  2365. but in ISO C it does not.
  2366. </li><li> In traditional C, some preprocessor directives did not exist.
  2367. Traditional preprocessors only considered a line to be a directive
  2368. if the &lsquo;<samp>#</samp>&rsquo; appeared in column 1 on the line. Therefore
  2369. <samp>-Wtraditional</samp> warns about directives that traditional C
  2370. understands but ignores because the &lsquo;<samp>#</samp>&rsquo; does not appear as the
  2371. first character on the line. It also suggests you hide directives like
  2372. <code>#pragma</code> not understood by traditional C by indenting them. Some
  2373. traditional implementations do not recognize <code>#elif</code>, so this option
  2374. suggests avoiding it altogether.
  2375. </li><li> A function-like macro that appears without arguments.
  2376. </li><li> The unary plus operator.
  2377. </li><li> The &lsquo;<samp>U</samp>&rsquo; integer constant suffix, or the &lsquo;<samp>F</samp>&rsquo; or &lsquo;<samp>L</samp>&rsquo; floating-point
  2378. constant suffixes. (Traditional C does support the &lsquo;<samp>L</samp>&rsquo; suffix on integer
  2379. constants.) Note, these suffixes appear in macros defined in the system
  2380. headers of most modern systems, e.g. the &lsquo;<samp>_MIN</samp>&rsquo;/&lsquo;<samp>_MAX</samp>&rsquo; macros in <code>&lt;limits.h&gt;</code>.
  2381. Use of these macros in user code might normally lead to spurious
  2382. warnings, however GCC&rsquo;s integrated preprocessor has enough context to
  2383. avoid warning in these cases.
  2384. </li><li> A function declared external in one block and then used after the end of
  2385. the block.
  2386. </li><li> A <code>switch</code> statement has an operand of type <code>long</code>.
  2387. </li><li> A non-<code>static</code> function declaration follows a <code>static</code> one.
  2388. This construct is not accepted by some traditional C compilers.
  2389. </li><li> The ISO type of an integer constant has a different width or
  2390. signedness from its traditional type. This warning is only issued if
  2391. the base of the constant is ten. I.e. hexadecimal or octal values, which
  2392. typically represent bit patterns, are not warned about.
  2393. </li><li> Usage of ISO string concatenation is detected.
  2394. </li><li> Initialization of automatic aggregates.
  2395. </li><li> Identifier conflicts with labels. Traditional C lacks a separate
  2396. namespace for labels.
  2397. </li><li> Initialization of unions. If the initializer is zero, the warning is
  2398. omitted. This is done under the assumption that the zero initializer in
  2399. user code appears conditioned on e.g. <code>__STDC__</code> to avoid missing
  2400. initializer warnings and relies on default initialization to zero in the
  2401. traditional C case.
  2402. </li><li> Conversions by prototypes between fixed/floating-point values and vice
  2403. versa. The absence of these prototypes when compiling with traditional
  2404. C causes serious problems. This is a subset of the possible
  2405. conversion warnings; for the full set use <samp>-Wtraditional-conversion</samp>.
  2406. </li><li> Use of ISO C style function definitions. This warning intentionally is
  2407. <em>not</em> issued for prototype declarations or variadic functions
  2408. because these ISO C features appear in your code when using
  2409. libiberty&rsquo;s traditional C compatibility macros, <code>PARAMS</code> and
  2410. <code>VPARAMS</code>. This warning is also bypassed for nested functions
  2411. because that feature is already a GCC extension and thus not relevant to
  2412. traditional C compatibility.
  2413. </li></ul>
  2414. </dd>
  2415. <dt><code>-Wtraditional-conversion <span class="roman">(C and Objective-C only)</span></code></dt>
  2416. <dd><a name="index-Wtraditional_002dconversion"></a>
  2417. <a name="index-Wno_002dtraditional_002dconversion"></a>
  2418. <p>Warn if a prototype causes a type conversion that is different from what
  2419. would happen to the same argument in the absence of a prototype. This
  2420. includes conversions of fixed point to floating and vice versa, and
  2421. conversions changing the width or signedness of a fixed-point argument
  2422. except when the same as the default promotion.
  2423. </p>
  2424. </dd>
  2425. <dt><code>-Wdeclaration-after-statement <span class="roman">(C and Objective-C only)</span></code></dt>
  2426. <dd><a name="index-Wdeclaration_002dafter_002dstatement"></a>
  2427. <a name="index-Wno_002ddeclaration_002dafter_002dstatement"></a>
  2428. <p>Warn when a declaration is found after a statement in a block. This
  2429. construct, known from C++, was introduced with ISO C99 and is by default
  2430. allowed in GCC. It is not supported by ISO C90. See <a href="Mixed-Declarations.html#Mixed-Declarations">Mixed Declarations</a>.
  2431. </p>
  2432. </dd>
  2433. <dt><code>-Wshadow</code></dt>
  2434. <dd><a name="index-Wshadow"></a>
  2435. <a name="index-Wno_002dshadow"></a>
  2436. <p>Warn whenever a local variable or type declaration shadows another
  2437. variable, parameter, type, class member (in C++), or instance variable
  2438. (in Objective-C) or whenever a built-in function is shadowed. Note
  2439. that in C++, the compiler warns if a local variable shadows an
  2440. explicit typedef, but not if it shadows a struct/class/enum.
  2441. If this warning is enabled, it includes also all instances of
  2442. local shadowing. This means that <samp>-Wno-shadow=local</samp>
  2443. and <samp>-Wno-shadow=compatible-local</samp> are ignored when
  2444. <samp>-Wshadow</samp> is used.
  2445. Same as <samp>-Wshadow=global</samp>.
  2446. </p>
  2447. </dd>
  2448. <dt><code>-Wno-shadow-ivar <span class="roman">(Objective-C only)</span></code></dt>
  2449. <dd><a name="index-Wno_002dshadow_002divar"></a>
  2450. <a name="index-Wshadow_002divar"></a>
  2451. <p>Do not warn whenever a local variable shadows an instance variable in an
  2452. Objective-C method.
  2453. </p>
  2454. </dd>
  2455. <dt><code>-Wshadow=global</code></dt>
  2456. <dd><a name="index-Wshadow_003dglobal"></a>
  2457. <p>Warn for any shadowing.
  2458. Same as <samp>-Wshadow</samp>.
  2459. </p>
  2460. </dd>
  2461. <dt><code>-Wshadow=local</code></dt>
  2462. <dd><a name="index-Wshadow_003dlocal"></a>
  2463. <p>Warn when a local variable shadows another local variable or parameter.
  2464. </p>
  2465. </dd>
  2466. <dt><code>-Wshadow=compatible-local</code></dt>
  2467. <dd><a name="index-Wshadow_003dcompatible_002dlocal"></a>
  2468. <p>Warn when a local variable shadows another local variable or parameter
  2469. whose type is compatible with that of the shadowing variable. In C++,
  2470. type compatibility here means the type of the shadowing variable can be
  2471. converted to that of the shadowed variable. The creation of this flag
  2472. (in addition to <samp>-Wshadow=local</samp>) is based on the idea that when
  2473. a local variable shadows another one of incompatible type, it is most
  2474. likely intentional, not a bug or typo, as shown in the following example:
  2475. </p>
  2476. <div class="smallexample">
  2477. <pre class="smallexample">for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
  2478. {
  2479. for (int i = 0; i &lt; N; ++i)
  2480. {
  2481. ...
  2482. }
  2483. ...
  2484. }
  2485. </pre></div>
  2486. <p>Since the two variable <code>i</code> in the example above have incompatible types,
  2487. enabling only <samp>-Wshadow=compatible-local</samp> does not emit a warning.
  2488. Because their types are incompatible, if a programmer accidentally uses one
  2489. in place of the other, type checking is expected to catch that and emit an
  2490. error or warning. Use of this flag instead of <samp>-Wshadow=local</samp> can
  2491. possibly reduce the number of warnings triggered by intentional shadowing.
  2492. Note that this also means that shadowing <code>const char *i</code> by
  2493. <code>char *i</code> does not emit a warning.
  2494. </p>
  2495. <p>This warning is also enabled by <samp>-Wshadow=local</samp>.
  2496. </p>
  2497. </dd>
  2498. <dt><code>-Wlarger-than=<var>byte-size</var></code></dt>
  2499. <dd><a name="index-Wlarger_002dthan_003d"></a>
  2500. <a name="index-Wlarger_002dthan_002dbyte_002dsize"></a>
  2501. <p>Warn whenever an object is defined whose size exceeds <var>byte-size</var>.
  2502. <samp>-Wlarger-than=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default.
  2503. Warnings controlled by the option can be disabled either by specifying
  2504. <var>byte-size</var> of &lsquo;<samp>SIZE_MAX</samp>&rsquo; or more or by
  2505. <samp>-Wno-larger-than</samp>.
  2506. </p>
  2507. </dd>
  2508. <dt><code>-Wno-larger-than</code></dt>
  2509. <dd><a name="index-Wno_002dlarger_002dthan"></a>
  2510. <p>Disable <samp>-Wlarger-than=</samp> warnings. The option is equivalent
  2511. to <samp>-Wlarger-than=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or larger.
  2512. </p>
  2513. </dd>
  2514. <dt><code>-Wframe-larger-than=<var>byte-size</var></code></dt>
  2515. <dd><a name="index-Wframe_002dlarger_002dthan_003d"></a>
  2516. <a name="index-Wno_002dframe_002dlarger_002dthan"></a>
  2517. <p>Warn if the size of a function frame exceeds <var>byte-size</var>.
  2518. The computation done to determine the stack frame size is approximate
  2519. and not conservative.
  2520. The actual requirements may be somewhat greater than <var>byte-size</var>
  2521. even if you do not get a warning. In addition, any space allocated
  2522. via <code>alloca</code>, variable-length arrays, or related constructs
  2523. is not included by the compiler when determining
  2524. whether or not to issue a warning.
  2525. <samp>-Wframe-larger-than=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default.
  2526. Warnings controlled by the option can be disabled either by specifying
  2527. <var>byte-size</var> of &lsquo;<samp>SIZE_MAX</samp>&rsquo; or more or by
  2528. <samp>-Wno-frame-larger-than</samp>.
  2529. </p>
  2530. </dd>
  2531. <dt><code>-Wno-frame-larger-than</code></dt>
  2532. <dd><a name="index-Wno_002dframe_002dlarger_002dthan-1"></a>
  2533. <p>Disable <samp>-Wframe-larger-than=</samp> warnings. The option is equivalent
  2534. to <samp>-Wframe-larger-than=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or larger.
  2535. </p>
  2536. </dd>
  2537. <dt><code>-Wno-free-nonheap-object</code></dt>
  2538. <dd><a name="index-Wno_002dfree_002dnonheap_002dobject"></a>
  2539. <a name="index-Wfree_002dnonheap_002dobject"></a>
  2540. <p>Do not warn when attempting to free an object that was not allocated
  2541. on the heap.
  2542. </p>
  2543. </dd>
  2544. <dt><code>-Wstack-usage=<var>byte-size</var></code></dt>
  2545. <dd><a name="index-Wstack_002dusage"></a>
  2546. <a name="index-Wno_002dstack_002dusage"></a>
  2547. <p>Warn if the stack usage of a function might exceed <var>byte-size</var>.
  2548. The computation done to determine the stack usage is conservative.
  2549. Any space allocated via <code>alloca</code>, variable-length arrays, or related
  2550. constructs is included by the compiler when determining whether or not to
  2551. issue a warning.
  2552. </p>
  2553. <p>The message is in keeping with the output of <samp>-fstack-usage</samp>.
  2554. </p>
  2555. <ul>
  2556. <li> If the stack usage is fully static but exceeds the specified amount, it&rsquo;s:
  2557. <div class="smallexample">
  2558. <pre class="smallexample"> warning: stack usage is 1120 bytes
  2559. </pre></div>
  2560. </li><li> If the stack usage is (partly) dynamic but bounded, it&rsquo;s:
  2561. <div class="smallexample">
  2562. <pre class="smallexample"> warning: stack usage might be 1648 bytes
  2563. </pre></div>
  2564. </li><li> If the stack usage is (partly) dynamic and not bounded, it&rsquo;s:
  2565. <div class="smallexample">
  2566. <pre class="smallexample"> warning: stack usage might be unbounded
  2567. </pre></div>
  2568. </li></ul>
  2569. <p><samp>-Wstack-usage=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default.
  2570. Warnings controlled by the option can be disabled either by specifying
  2571. <var>byte-size</var> of &lsquo;<samp>SIZE_MAX</samp>&rsquo; or more or by
  2572. <samp>-Wno-stack-usage</samp>.
  2573. </p>
  2574. </dd>
  2575. <dt><code>-Wno-stack-usage</code></dt>
  2576. <dd><a name="index-Wno_002dstack_002dusage-1"></a>
  2577. <p>Disable <samp>-Wstack-usage=</samp> warnings. The option is equivalent
  2578. to <samp>-Wstack-usage=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or larger.
  2579. </p>
  2580. </dd>
  2581. <dt><code>-Wunsafe-loop-optimizations</code></dt>
  2582. <dd><a name="index-Wunsafe_002dloop_002doptimizations"></a>
  2583. <a name="index-Wno_002dunsafe_002dloop_002doptimizations"></a>
  2584. <p>Warn if the loop cannot be optimized because the compiler cannot
  2585. assume anything on the bounds of the loop indices. With
  2586. <samp>-funsafe-loop-optimizations</samp> warn if the compiler makes
  2587. such assumptions.
  2588. </p>
  2589. </dd>
  2590. <dt><code>-Wno-pedantic-ms-format <span class="roman">(MinGW targets only)</span></code></dt>
  2591. <dd><a name="index-Wno_002dpedantic_002dms_002dformat"></a>
  2592. <a name="index-Wpedantic_002dms_002dformat"></a>
  2593. <p>When used in combination with <samp>-Wformat</samp>
  2594. and <samp>-pedantic</samp> without GNU extensions, this option
  2595. disables the warnings about non-ISO <code>printf</code> / <code>scanf</code> format
  2596. width specifiers <code>I32</code>, <code>I64</code>, and <code>I</code> used on Windows targets,
  2597. which depend on the MS runtime.
  2598. </p>
  2599. </dd>
  2600. <dt><code>-Wpointer-arith</code></dt>
  2601. <dd><a name="index-Wpointer_002darith"></a>
  2602. <a name="index-Wno_002dpointer_002darith"></a>
  2603. <p>Warn about anything that depends on the &ldquo;size of&rdquo; a function type or
  2604. of <code>void</code>. GNU C assigns these types a size of 1, for
  2605. convenience in calculations with <code>void *</code> pointers and pointers
  2606. to functions. In C++, warn also when an arithmetic operation involves
  2607. <code>NULL</code>. This warning is also enabled by <samp>-Wpedantic</samp>.
  2608. </p>
  2609. </dd>
  2610. <dt><code>-Wno-pointer-compare</code></dt>
  2611. <dd><a name="index-Wpointer_002dcompare"></a>
  2612. <a name="index-Wno_002dpointer_002dcompare"></a>
  2613. <p>Do not warn if a pointer is compared with a zero character constant.
  2614. This usually
  2615. means that the pointer was meant to be dereferenced. For example:
  2616. </p>
  2617. <div class="smallexample">
  2618. <pre class="smallexample">const char *p = foo ();
  2619. if (p == '\0')
  2620. return 42;
  2621. </pre></div>
  2622. <p>Note that the code above is invalid in C++11.
  2623. </p>
  2624. <p>This warning is enabled by default.
  2625. </p>
  2626. </dd>
  2627. <dt><code>-Wtype-limits</code></dt>
  2628. <dd><a name="index-Wtype_002dlimits"></a>
  2629. <a name="index-Wno_002dtype_002dlimits"></a>
  2630. <p>Warn if a comparison is always true or always false due to the limited
  2631. range of the data type, but do not warn for constant expressions. For
  2632. example, warn if an unsigned variable is compared against zero with
  2633. <code>&lt;</code> or <code>&gt;=</code>. This warning is also enabled by
  2634. <samp>-Wextra</samp>.
  2635. </p>
  2636. </dd>
  2637. <dt><code>-Wabsolute-value <span class="roman">(C and Objective-C only)</span></code></dt>
  2638. <dd><a name="index-Wabsolute_002dvalue"></a>
  2639. <a name="index-Wno_002dabsolute_002dvalue"></a>
  2640. <p>Warn for calls to standard functions that compute the absolute value
  2641. of an argument when a more appropriate standard function is available.
  2642. For example, calling <code>abs(3.14)</code> triggers the warning because the
  2643. appropriate function to call to compute the absolute value of a double
  2644. argument is <code>fabs</code>. The option also triggers warnings when the
  2645. argument in a call to such a function has an unsigned type. This
  2646. warning can be suppressed with an explicit type cast and it is also
  2647. enabled by <samp>-Wextra</samp>.
  2648. </p>
  2649. </dd>
  2650. <dt><code>-Wcomment</code></dt>
  2651. <dt><code>-Wcomments</code></dt>
  2652. <dd><a name="index-Wcomment"></a>
  2653. <a name="index-Wcomments"></a>
  2654. <p>Warn whenever a comment-start sequence &lsquo;<samp>/*</samp>&rsquo; appears in a &lsquo;<samp>/*</samp>&rsquo;
  2655. comment, or whenever a backslash-newline appears in a &lsquo;<samp>//</samp>&rsquo; comment.
  2656. This warning is enabled by <samp>-Wall</samp>.
  2657. </p>
  2658. </dd>
  2659. <dt><code>-Wtrigraphs</code></dt>
  2660. <dd><a name="index-Wtrigraphs"></a>
  2661. <a name="Wtrigraphs"></a><p>Warn if any trigraphs are encountered that might change the meaning of
  2662. the program. Trigraphs within comments are not warned about,
  2663. except those that would form escaped newlines.
  2664. </p>
  2665. <p>This option is implied by <samp>-Wall</samp>. If <samp>-Wall</samp> is not
  2666. given, this option is still enabled unless trigraphs are enabled. To
  2667. get trigraph conversion without warnings, but get the other
  2668. <samp>-Wall</samp> warnings, use &lsquo;<samp>-trigraphs -Wall -Wno-trigraphs</samp>&rsquo;.
  2669. </p>
  2670. </dd>
  2671. <dt><code>-Wundef</code></dt>
  2672. <dd><a name="index-Wundef"></a>
  2673. <a name="index-Wno_002dundef"></a>
  2674. <p>Warn if an undefined identifier is evaluated in an <code>#if</code> directive.
  2675. Such identifiers are replaced with zero.
  2676. </p>
  2677. </dd>
  2678. <dt><code>-Wexpansion-to-defined</code></dt>
  2679. <dd><a name="index-Wexpansion_002dto_002ddefined"></a>
  2680. <p>Warn whenever &lsquo;<samp>defined</samp>&rsquo; is encountered in the expansion of a macro
  2681. (including the case where the macro is expanded by an &lsquo;<samp>#if</samp>&rsquo; directive).
  2682. Such usage is not portable.
  2683. This warning is also enabled by <samp>-Wpedantic</samp> and <samp>-Wextra</samp>.
  2684. </p>
  2685. </dd>
  2686. <dt><code>-Wunused-macros</code></dt>
  2687. <dd><a name="index-Wunused_002dmacros"></a>
  2688. <p>Warn about macros defined in the main file that are unused. A macro
  2689. is <em>used</em> if it is expanded or tested for existence at least once.
  2690. The preprocessor also warns if the macro has not been used at the
  2691. time it is redefined or undefined.
  2692. </p>
  2693. <p>Built-in macros, macros defined on the command line, and macros
  2694. defined in include files are not warned about.
  2695. </p>
  2696. <p><em>Note:</em> If a macro is actually used, but only used in skipped
  2697. conditional blocks, then the preprocessor reports it as unused. To avoid the
  2698. warning in such a case, you might improve the scope of the macro&rsquo;s
  2699. definition by, for example, moving it into the first skipped block.
  2700. Alternatively, you could provide a dummy use with something like:
  2701. </p>
  2702. <div class="smallexample">
  2703. <pre class="smallexample">#if defined the_macro_causing_the_warning
  2704. #endif
  2705. </pre></div>
  2706. </dd>
  2707. <dt><code>-Wno-endif-labels</code></dt>
  2708. <dd><a name="index-Wno_002dendif_002dlabels"></a>
  2709. <a name="index-Wendif_002dlabels"></a>
  2710. <p>Do not warn whenever an <code>#else</code> or an <code>#endif</code> are followed by text.
  2711. This sometimes happens in older programs with code of the form
  2712. </p>
  2713. <div class="smallexample">
  2714. <pre class="smallexample">#if FOO
  2715. &hellip;
  2716. #else FOO
  2717. &hellip;
  2718. #endif FOO
  2719. </pre></div>
  2720. <p>The second and third <code>FOO</code> should be in comments.
  2721. This warning is on by default.
  2722. </p>
  2723. </dd>
  2724. <dt><code>-Wbad-function-cast <span class="roman">(C and Objective-C only)</span></code></dt>
  2725. <dd><a name="index-Wbad_002dfunction_002dcast"></a>
  2726. <a name="index-Wno_002dbad_002dfunction_002dcast"></a>
  2727. <p>Warn when a function call is cast to a non-matching type.
  2728. For example, warn if a call to a function returning an integer type
  2729. is cast to a pointer type.
  2730. </p>
  2731. </dd>
  2732. <dt><code>-Wc90-c99-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2733. <dd><a name="index-Wc90_002dc99_002dcompat"></a>
  2734. <a name="index-Wno_002dc90_002dc99_002dcompat"></a>
  2735. <p>Warn about features not present in ISO C90, but present in ISO C99.
  2736. For instance, warn about use of variable length arrays, <code>long long</code>
  2737. type, <code>bool</code> type, compound literals, designated initializers, and so
  2738. on. This option is independent of the standards mode. Warnings are disabled
  2739. in the expression that follows <code>__extension__</code>.
  2740. </p>
  2741. </dd>
  2742. <dt><code>-Wc99-c11-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2743. <dd><a name="index-Wc99_002dc11_002dcompat"></a>
  2744. <a name="index-Wno_002dc99_002dc11_002dcompat"></a>
  2745. <p>Warn about features not present in ISO C99, but present in ISO C11.
  2746. For instance, warn about use of anonymous structures and unions,
  2747. <code>_Atomic</code> type qualifier, <code>_Thread_local</code> storage-class specifier,
  2748. <code>_Alignas</code> specifier, <code>Alignof</code> operator, <code>_Generic</code> keyword,
  2749. and so on. This option is independent of the standards mode. Warnings are
  2750. disabled in the expression that follows <code>__extension__</code>.
  2751. </p>
  2752. </dd>
  2753. <dt><code>-Wc11-c2x-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2754. <dd><a name="index-Wc11_002dc2x_002dcompat"></a>
  2755. <a name="index-Wno_002dc11_002dc2x_002dcompat"></a>
  2756. <p>Warn about features not present in ISO C11, but present in ISO C2X.
  2757. For instance, warn about omitting the string in <code>_Static_assert</code>,
  2758. use of &lsquo;<samp>[[]]</samp>&rsquo; syntax for attributes, use of decimal
  2759. floating-point types, and so on. This option is independent of the
  2760. standards mode. Warnings are disabled in the expression that follows
  2761. <code>__extension__</code>.
  2762. </p>
  2763. </dd>
  2764. <dt><code>-Wc++-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2765. <dd><a name="index-Wc_002b_002b_002dcompat"></a>
  2766. <a name="index-Wno_002dc_002b_002b_002dcompat"></a>
  2767. <p>Warn about ISO C constructs that are outside of the common subset of
  2768. ISO C and ISO C++, e.g. request for implicit conversion from
  2769. <code>void *</code> to a pointer to non-<code>void</code> type.
  2770. </p>
  2771. </dd>
  2772. <dt><code>-Wc++11-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2773. <dd><a name="index-Wc_002b_002b11_002dcompat"></a>
  2774. <a name="index-Wno_002dc_002b_002b11_002dcompat"></a>
  2775. <p>Warn about C++ constructs whose meaning differs between ISO C++ 1998
  2776. and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are keywords
  2777. in ISO C++ 2011. This warning turns on <samp>-Wnarrowing</samp> and is
  2778. enabled by <samp>-Wall</samp>.
  2779. </p>
  2780. </dd>
  2781. <dt><code>-Wc++14-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2782. <dd><a name="index-Wc_002b_002b14_002dcompat"></a>
  2783. <a name="index-Wno_002dc_002b_002b14_002dcompat"></a>
  2784. <p>Warn about C++ constructs whose meaning differs between ISO C++ 2011
  2785. and ISO C++ 2014. This warning is enabled by <samp>-Wall</samp>.
  2786. </p>
  2787. </dd>
  2788. <dt><code>-Wc++17-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2789. <dd><a name="index-Wc_002b_002b17_002dcompat"></a>
  2790. <a name="index-Wno_002dc_002b_002b17_002dcompat"></a>
  2791. <p>Warn about C++ constructs whose meaning differs between ISO C++ 2014
  2792. and ISO C++ 2017. This warning is enabled by <samp>-Wall</samp>.
  2793. </p>
  2794. </dd>
  2795. <dt><code>-Wc++20-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2796. <dd><a name="index-Wc_002b_002b20_002dcompat"></a>
  2797. <a name="index-Wno_002dc_002b_002b20_002dcompat"></a>
  2798. <p>Warn about C++ constructs whose meaning differs between ISO C++ 2017
  2799. and ISO C++ 2020. This warning is enabled by <samp>-Wall</samp>.
  2800. </p>
  2801. </dd>
  2802. <dt><code>-Wcast-qual</code></dt>
  2803. <dd><a name="index-Wcast_002dqual"></a>
  2804. <a name="index-Wno_002dcast_002dqual"></a>
  2805. <p>Warn whenever a pointer is cast so as to remove a type qualifier from
  2806. the target type. For example, warn if a <code>const char *</code> is cast
  2807. to an ordinary <code>char *</code>.
  2808. </p>
  2809. <p>Also warn when making a cast that introduces a type qualifier in an
  2810. unsafe way. For example, casting <code>char **</code> to <code>const char **</code>
  2811. is unsafe, as in this example:
  2812. </p>
  2813. <div class="smallexample">
  2814. <pre class="smallexample"> /* p is char ** value. */
  2815. const char **q = (const char **) p;
  2816. /* Assignment of readonly string to const char * is OK. */
  2817. *q = &quot;string&quot;;
  2818. /* Now char** pointer points to read-only memory. */
  2819. **p = 'b';
  2820. </pre></div>
  2821. </dd>
  2822. <dt><code>-Wcast-align</code></dt>
  2823. <dd><a name="index-Wcast_002dalign"></a>
  2824. <a name="index-Wno_002dcast_002dalign"></a>
  2825. <p>Warn whenever a pointer is cast such that the required alignment of the
  2826. target is increased. For example, warn if a <code>char *</code> is cast to
  2827. an <code>int *</code> on machines where integers can only be accessed at
  2828. two- or four-byte boundaries.
  2829. </p>
  2830. </dd>
  2831. <dt><code>-Wcast-align=strict</code></dt>
  2832. <dd><a name="index-Wcast_002dalign_003dstrict"></a>
  2833. <p>Warn whenever a pointer is cast such that the required alignment of the
  2834. target is increased. For example, warn if a <code>char *</code> is cast to
  2835. an <code>int *</code> regardless of the target machine.
  2836. </p>
  2837. </dd>
  2838. <dt><code>-Wcast-function-type</code></dt>
  2839. <dd><a name="index-Wcast_002dfunction_002dtype"></a>
  2840. <a name="index-Wno_002dcast_002dfunction_002dtype"></a>
  2841. <p>Warn when a function pointer is cast to an incompatible function pointer.
  2842. In a cast involving function types with a variable argument list only
  2843. the types of initial arguments that are provided are considered.
  2844. Any parameter of pointer-type matches any other pointer-type. Any benign
  2845. differences in integral types are ignored, like <code>int</code> vs. <code>long</code>
  2846. on ILP32 targets. Likewise type qualifiers are ignored. The function
  2847. type <code>void (*) (void)</code> is special and matches everything, which can
  2848. be used to suppress this warning.
  2849. In a cast involving pointer to member types this warning warns whenever
  2850. the type cast is changing the pointer to member type.
  2851. This warning is enabled by <samp>-Wextra</samp>.
  2852. </p>
  2853. </dd>
  2854. <dt><code>-Wwrite-strings</code></dt>
  2855. <dd><a name="index-Wwrite_002dstrings"></a>
  2856. <a name="index-Wno_002dwrite_002dstrings"></a>
  2857. <p>When compiling C, give string constants the type <code>const
  2858. char[<var>length</var>]</code> so that copying the address of one into a
  2859. non-<code>const</code> <code>char *</code> pointer produces a warning. These
  2860. warnings help you find at compile time code that can try to write
  2861. into a string constant, but only if you have been very careful about
  2862. using <code>const</code> in declarations and prototypes. Otherwise, it is
  2863. just a nuisance. This is why we did not make <samp>-Wall</samp> request
  2864. these warnings.
  2865. </p>
  2866. <p>When compiling C++, warn about the deprecated conversion from string
  2867. literals to <code>char *</code>. This warning is enabled by default for C++
  2868. programs.
  2869. </p>
  2870. </dd>
  2871. <dt><code>-Wclobbered</code></dt>
  2872. <dd><a name="index-Wclobbered"></a>
  2873. <a name="index-Wno_002dclobbered"></a>
  2874. <p>Warn for variables that might be changed by <code>longjmp</code> or
  2875. <code>vfork</code>. This warning is also enabled by <samp>-Wextra</samp>.
  2876. </p>
  2877. </dd>
  2878. <dt><code>-Wconversion</code></dt>
  2879. <dd><a name="index-Wconversion"></a>
  2880. <a name="index-Wno_002dconversion"></a>
  2881. <p>Warn for implicit conversions that may alter a value. This includes
  2882. conversions between real and integer, like <code>abs (x)</code> when
  2883. <code>x</code> is <code>double</code>; conversions between signed and unsigned,
  2884. like <code>unsigned ui = -1</code>; and conversions to smaller types, like
  2885. <code>sqrtf (M_PI)</code>. Do not warn for explicit casts like <code>abs
  2886. ((int) x)</code> and <code>ui = (unsigned) -1</code>, or if the value is not
  2887. changed by the conversion like in <code>abs (2.0)</code>. Warnings about
  2888. conversions between signed and unsigned integers can be disabled by
  2889. using <samp>-Wno-sign-conversion</samp>.
  2890. </p>
  2891. <p>For C++, also warn for confusing overload resolution for user-defined
  2892. conversions; and conversions that never use a type conversion
  2893. operator: conversions to <code>void</code>, the same type, a base class or a
  2894. reference to them. Warnings about conversions between signed and
  2895. unsigned integers are disabled by default in C++ unless
  2896. <samp>-Wsign-conversion</samp> is explicitly enabled.
  2897. </p>
  2898. <p>Warnings about conversion from arithmetic on a small type back to that
  2899. type are only given with <samp>-Warith-conversion</samp>.
  2900. </p>
  2901. </dd>
  2902. <dt><code>-Wdangling-else</code></dt>
  2903. <dd><a name="index-Wdangling_002delse"></a>
  2904. <a name="index-Wno_002ddangling_002delse"></a>
  2905. <p>Warn about constructions where there may be confusion to which
  2906. <code>if</code> statement an <code>else</code> branch belongs. Here is an example of
  2907. such a case:
  2908. </p>
  2909. <div class="smallexample">
  2910. <pre class="smallexample">{
  2911. if (a)
  2912. if (b)
  2913. foo ();
  2914. else
  2915. bar ();
  2916. }
  2917. </pre></div>
  2918. <p>In C/C++, every <code>else</code> branch belongs to the innermost possible
  2919. <code>if</code> statement, which in this example is <code>if (b)</code>. This is
  2920. often not what the programmer expected, as illustrated in the above
  2921. example by indentation the programmer chose. When there is the
  2922. potential for this confusion, GCC issues a warning when this flag
  2923. is specified. To eliminate the warning, add explicit braces around
  2924. the innermost <code>if</code> statement so there is no way the <code>else</code>
  2925. can belong to the enclosing <code>if</code>. The resulting code
  2926. looks like this:
  2927. </p>
  2928. <div class="smallexample">
  2929. <pre class="smallexample">{
  2930. if (a)
  2931. {
  2932. if (b)
  2933. foo ();
  2934. else
  2935. bar ();
  2936. }
  2937. }
  2938. </pre></div>
  2939. <p>This warning is enabled by <samp>-Wparentheses</samp>.
  2940. </p>
  2941. </dd>
  2942. <dt><code>-Wdate-time</code></dt>
  2943. <dd><a name="index-Wdate_002dtime"></a>
  2944. <a name="index-Wno_002ddate_002dtime"></a>
  2945. <p>Warn when macros <code>__TIME__</code>, <code>__DATE__</code> or <code>__TIMESTAMP__</code>
  2946. are encountered as they might prevent bit-wise-identical reproducible
  2947. compilations.
  2948. </p>
  2949. </dd>
  2950. <dt><code>-Wempty-body</code></dt>
  2951. <dd><a name="index-Wempty_002dbody"></a>
  2952. <a name="index-Wno_002dempty_002dbody"></a>
  2953. <p>Warn if an empty body occurs in an <code>if</code>, <code>else</code> or <code>do
  2954. while</code> statement. This warning is also enabled by <samp>-Wextra</samp>.
  2955. </p>
  2956. </dd>
  2957. <dt><code>-Wno-endif-labels</code></dt>
  2958. <dd><a name="index-Wendif_002dlabels-1"></a>
  2959. <a name="index-Wno_002dendif_002dlabels-1"></a>
  2960. <p>Do not warn about stray tokens after <code>#else</code> and <code>#endif</code>.
  2961. </p>
  2962. </dd>
  2963. <dt><code>-Wenum-compare</code></dt>
  2964. <dd><a name="index-Wenum_002dcompare"></a>
  2965. <a name="index-Wno_002denum_002dcompare"></a>
  2966. <p>Warn about a comparison between values of different enumerated types.
  2967. In C++ enumerated type mismatches in conditional expressions are also
  2968. diagnosed and the warning is enabled by default. In C this warning is
  2969. enabled by <samp>-Wall</samp>.
  2970. </p>
  2971. </dd>
  2972. <dt><code>-Wenum-conversion <span class="roman">(C, Objective-C only)</span></code></dt>
  2973. <dd><a name="index-Wenum_002dconversion"></a>
  2974. <a name="index-Wno_002denum_002dconversion"></a>
  2975. <p>Warn when a value of enumerated type is implicitly converted to a
  2976. different enumerated type. This warning is enabled by <samp>-Wextra</samp>.
  2977. </p>
  2978. </dd>
  2979. <dt><code>-Wjump-misses-init <span class="roman">(C, Objective-C only)</span></code></dt>
  2980. <dd><a name="index-Wjump_002dmisses_002dinit"></a>
  2981. <a name="index-Wno_002djump_002dmisses_002dinit"></a>
  2982. <p>Warn if a <code>goto</code> statement or a <code>switch</code> statement jumps
  2983. forward across the initialization of a variable, or jumps backward to a
  2984. label after the variable has been initialized. This only warns about
  2985. variables that are initialized when they are declared. This warning is
  2986. only supported for C and Objective-C; in C++ this sort of branch is an
  2987. error in any case.
  2988. </p>
  2989. <p><samp>-Wjump-misses-init</samp> is included in <samp>-Wc++-compat</samp>. It
  2990. can be disabled with the <samp>-Wno-jump-misses-init</samp> option.
  2991. </p>
  2992. </dd>
  2993. <dt><code>-Wsign-compare</code></dt>
  2994. <dd><a name="index-Wsign_002dcompare"></a>
  2995. <a name="index-Wno_002dsign_002dcompare"></a>
  2996. <a name="index-warning-for-comparison-of-signed-and-unsigned-values"></a>
  2997. <a name="index-comparison-of-signed-and-unsigned-values_002c-warning"></a>
  2998. <a name="index-signed-and-unsigned-values_002c-comparison-warning"></a>
  2999. <p>Warn when a comparison between signed and unsigned values could produce
  3000. an incorrect result when the signed value is converted to unsigned.
  3001. In C++, this warning is also enabled by <samp>-Wall</samp>. In C, it is
  3002. also enabled by <samp>-Wextra</samp>.
  3003. </p>
  3004. </dd>
  3005. <dt><code>-Wsign-conversion</code></dt>
  3006. <dd><a name="index-Wsign_002dconversion"></a>
  3007. <a name="index-Wno_002dsign_002dconversion"></a>
  3008. <p>Warn for implicit conversions that may change the sign of an integer
  3009. value, like assigning a signed integer expression to an unsigned
  3010. integer variable. An explicit cast silences the warning. In C, this
  3011. option is enabled also by <samp>-Wconversion</samp>.
  3012. </p>
  3013. </dd>
  3014. <dt><code>-Wfloat-conversion</code></dt>
  3015. <dd><a name="index-Wfloat_002dconversion"></a>
  3016. <a name="index-Wno_002dfloat_002dconversion"></a>
  3017. <p>Warn for implicit conversions that reduce the precision of a real value.
  3018. This includes conversions from real to integer, and from higher precision
  3019. real to lower precision real values. This option is also enabled by
  3020. <samp>-Wconversion</samp>.
  3021. </p>
  3022. </dd>
  3023. <dt><code>-Wno-scalar-storage-order</code></dt>
  3024. <dd><a name="index-Wno_002dscalar_002dstorage_002dorder"></a>
  3025. <a name="index-Wscalar_002dstorage_002dorder"></a>
  3026. <p>Do not warn on suspicious constructs involving reverse scalar storage order.
  3027. </p>
  3028. </dd>
  3029. <dt><code>-Wsizeof-pointer-div</code></dt>
  3030. <dd><a name="index-Wsizeof_002dpointer_002ddiv"></a>
  3031. <a name="index-Wno_002dsizeof_002dpointer_002ddiv"></a>
  3032. <p>Warn for suspicious divisions of two sizeof expressions that divide
  3033. the pointer size by the element size, which is the usual way to compute
  3034. the array size but won&rsquo;t work out correctly with pointers. This warning
  3035. warns e.g. about <code>sizeof (ptr) / sizeof (ptr[0])</code> if <code>ptr</code> is
  3036. not an array, but a pointer. This warning is enabled by <samp>-Wall</samp>.
  3037. </p>
  3038. </dd>
  3039. <dt><code>-Wsizeof-pointer-memaccess</code></dt>
  3040. <dd><a name="index-Wsizeof_002dpointer_002dmemaccess"></a>
  3041. <a name="index-Wno_002dsizeof_002dpointer_002dmemaccess"></a>
  3042. <p>Warn for suspicious length parameters to certain string and memory built-in
  3043. functions if the argument uses <code>sizeof</code>. This warning triggers for
  3044. example for <code>memset (ptr, 0, sizeof (ptr));</code> if <code>ptr</code> is not
  3045. an array, but a pointer, and suggests a possible fix, or about
  3046. <code>memcpy (&amp;foo, ptr, sizeof (&amp;foo));</code>. <samp>-Wsizeof-pointer-memaccess</samp>
  3047. also warns about calls to bounded string copy functions like <code>strncat</code>
  3048. or <code>strncpy</code> that specify as the bound a <code>sizeof</code> expression of
  3049. the source array. For example, in the following function the call to
  3050. <code>strncat</code> specifies the size of the source string as the bound. That
  3051. is almost certainly a mistake and so the call is diagnosed.
  3052. </p><div class="smallexample">
  3053. <pre class="smallexample">void make_file (const char *name)
  3054. {
  3055. char path[PATH_MAX];
  3056. strncpy (path, name, sizeof path - 1);
  3057. strncat (path, &quot;.text&quot;, sizeof &quot;.text&quot;);
  3058. &hellip;
  3059. }
  3060. </pre></div>
  3061. <p>The <samp>-Wsizeof-pointer-memaccess</samp> option is enabled by <samp>-Wall</samp>.
  3062. </p>
  3063. </dd>
  3064. <dt><code>-Wno-sizeof-array-argument</code></dt>
  3065. <dd><a name="index-Wsizeof_002darray_002dargument"></a>
  3066. <a name="index-Wno_002dsizeof_002darray_002dargument"></a>
  3067. <p>Do not warn when the <code>sizeof</code> operator is applied to a parameter that is
  3068. declared as an array in a function definition. This warning is enabled by
  3069. default for C and C++ programs.
  3070. </p>
  3071. </dd>
  3072. <dt><code>-Wmemset-elt-size</code></dt>
  3073. <dd><a name="index-Wmemset_002delt_002dsize"></a>
  3074. <a name="index-Wno_002dmemset_002delt_002dsize"></a>
  3075. <p>Warn for suspicious calls to the <code>memset</code> built-in function, if the
  3076. first argument references an array, and the third argument is a number
  3077. equal to the number of elements, but not equal to the size of the array
  3078. in memory. This indicates that the user has omitted a multiplication by
  3079. the element size. This warning is enabled by <samp>-Wall</samp>.
  3080. </p>
  3081. </dd>
  3082. <dt><code>-Wmemset-transposed-args</code></dt>
  3083. <dd><a name="index-Wmemset_002dtransposed_002dargs"></a>
  3084. <a name="index-Wno_002dmemset_002dtransposed_002dargs"></a>
  3085. <p>Warn for suspicious calls to the <code>memset</code> built-in function where
  3086. the second argument is not zero and the third argument is zero. For
  3087. example, the call <code>memset (buf, sizeof buf, 0)</code> is diagnosed because
  3088. <code>memset (buf, 0, sizeof buf)</code> was meant instead. The diagnostic
  3089. is only emitted if the third argument is a literal zero. Otherwise, if
  3090. it is an expression that is folded to zero, or a cast of zero to some
  3091. type, it is far less likely that the arguments have been mistakenly
  3092. transposed and no warning is emitted. This warning is enabled
  3093. by <samp>-Wall</samp>.
  3094. </p>
  3095. </dd>
  3096. <dt><code>-Waddress</code></dt>
  3097. <dd><a name="index-Waddress"></a>
  3098. <a name="index-Wno_002daddress"></a>
  3099. <p>Warn about suspicious uses of memory addresses. These include using
  3100. the address of a function in a conditional expression, such as
  3101. <code>void func(void); if (func)</code>, and comparisons against the memory
  3102. address of a string literal, such as <code>if (x == &quot;abc&quot;)</code>. Such
  3103. uses typically indicate a programmer error: the address of a function
  3104. always evaluates to true, so their use in a conditional usually
  3105. indicate that the programmer forgot the parentheses in a function
  3106. call; and comparisons against string literals result in unspecified
  3107. behavior and are not portable in C, so they usually indicate that the
  3108. programmer intended to use <code>strcmp</code>. This warning is enabled by
  3109. <samp>-Wall</samp>.
  3110. </p>
  3111. </dd>
  3112. <dt><code>-Wno-address-of-packed-member</code></dt>
  3113. <dd><a name="index-Waddress_002dof_002dpacked_002dmember"></a>
  3114. <a name="index-Wno_002daddress_002dof_002dpacked_002dmember"></a>
  3115. <p>Do not warn when the address of packed member of struct or union is taken,
  3116. which usually results in an unaligned pointer value. This is
  3117. enabled by default.
  3118. </p>
  3119. </dd>
  3120. <dt><code>-Wlogical-op</code></dt>
  3121. <dd><a name="index-Wlogical_002dop"></a>
  3122. <a name="index-Wno_002dlogical_002dop"></a>
  3123. <p>Warn about suspicious uses of logical operators in expressions.
  3124. This includes using logical operators in contexts where a
  3125. bit-wise operator is likely to be expected. Also warns when
  3126. the operands of a logical operator are the same:
  3127. </p><div class="smallexample">
  3128. <pre class="smallexample">extern int a;
  3129. if (a &lt; 0 &amp;&amp; a &lt; 0) { &hellip; }
  3130. </pre></div>
  3131. </dd>
  3132. <dt><code>-Wlogical-not-parentheses</code></dt>
  3133. <dd><a name="index-Wlogical_002dnot_002dparentheses"></a>
  3134. <a name="index-Wno_002dlogical_002dnot_002dparentheses"></a>
  3135. <p>Warn about logical not used on the left hand side operand of a comparison.
  3136. This option does not warn if the right operand is considered to be a boolean
  3137. expression. Its purpose is to detect suspicious code like the following:
  3138. </p><div class="smallexample">
  3139. <pre class="smallexample">int a;
  3140. &hellip;
  3141. if (!a &gt; 1) { &hellip; }
  3142. </pre></div>
  3143. <p>It is possible to suppress the warning by wrapping the LHS into
  3144. parentheses:
  3145. </p><div class="smallexample">
  3146. <pre class="smallexample">if ((!a) &gt; 1) { &hellip; }
  3147. </pre></div>
  3148. <p>This warning is enabled by <samp>-Wall</samp>.
  3149. </p>
  3150. </dd>
  3151. <dt><code>-Waggregate-return</code></dt>
  3152. <dd><a name="index-Waggregate_002dreturn"></a>
  3153. <a name="index-Wno_002daggregate_002dreturn"></a>
  3154. <p>Warn if any functions that return structures or unions are defined or
  3155. called. (In languages where you can return an array, this also elicits
  3156. a warning.)
  3157. </p>
  3158. </dd>
  3159. <dt><code>-Wno-aggressive-loop-optimizations</code></dt>
  3160. <dd><a name="index-Wno_002daggressive_002dloop_002doptimizations"></a>
  3161. <a name="index-Waggressive_002dloop_002doptimizations"></a>
  3162. <p>Warn if in a loop with constant number of iterations the compiler detects
  3163. undefined behavior in some statement during one or more of the iterations.
  3164. </p>
  3165. </dd>
  3166. <dt><code>-Wno-attributes</code></dt>
  3167. <dd><a name="index-Wno_002dattributes"></a>
  3168. <a name="index-Wattributes"></a>
  3169. <p>Do not warn if an unexpected <code>__attribute__</code> is used, such as
  3170. unrecognized attributes, function attributes applied to variables,
  3171. etc. This does not stop errors for incorrect use of supported
  3172. attributes.
  3173. </p>
  3174. </dd>
  3175. <dt><code>-Wno-builtin-declaration-mismatch</code></dt>
  3176. <dd><a name="index-Wno_002dbuiltin_002ddeclaration_002dmismatch"></a>
  3177. <a name="index-Wbuiltin_002ddeclaration_002dmismatch"></a>
  3178. <p>Warn if a built-in function is declared with an incompatible signature
  3179. or as a non-function, or when a built-in function declared with a type
  3180. that does not include a prototype is called with arguments whose promoted
  3181. types do not match those expected by the function. When <samp>-Wextra</samp>
  3182. is specified, also warn when a built-in function that takes arguments is
  3183. declared without a prototype. The <samp>-Wbuiltin-declaration-mismatch</samp>
  3184. warning is enabled by default. To avoid the warning include the appropriate
  3185. header to bring the prototypes of built-in functions into scope.
  3186. </p>
  3187. <p>For example, the call to <code>memset</code> below is diagnosed by the warning
  3188. because the function expects a value of type <code>size_t</code> as its argument
  3189. but the type of <code>32</code> is <code>int</code>. With <samp>-Wextra</samp>,
  3190. the declaration of the function is diagnosed as well.
  3191. </p><div class="smallexample">
  3192. <pre class="smallexample">extern void* memset ();
  3193. void f (void *d)
  3194. {
  3195. memset (d, '\0', 32);
  3196. }
  3197. </pre></div>
  3198. </dd>
  3199. <dt><code>-Wno-builtin-macro-redefined</code></dt>
  3200. <dd><a name="index-Wno_002dbuiltin_002dmacro_002dredefined"></a>
  3201. <a name="index-Wbuiltin_002dmacro_002dredefined"></a>
  3202. <p>Do not warn if certain built-in macros are redefined. This suppresses
  3203. warnings for redefinition of <code>__TIMESTAMP__</code>, <code>__TIME__</code>,
  3204. <code>__DATE__</code>, <code>__FILE__</code>, and <code>__BASE_FILE__</code>.
  3205. </p>
  3206. </dd>
  3207. <dt><code>-Wstrict-prototypes <span class="roman">(C and Objective-C only)</span></code></dt>
  3208. <dd><a name="index-Wstrict_002dprototypes"></a>
  3209. <a name="index-Wno_002dstrict_002dprototypes"></a>
  3210. <p>Warn if a function is declared or defined without specifying the
  3211. argument types. (An old-style function definition is permitted without
  3212. a warning if preceded by a declaration that specifies the argument
  3213. types.)
  3214. </p>
  3215. </dd>
  3216. <dt><code>-Wold-style-declaration <span class="roman">(C and Objective-C only)</span></code></dt>
  3217. <dd><a name="index-Wold_002dstyle_002ddeclaration"></a>
  3218. <a name="index-Wno_002dold_002dstyle_002ddeclaration"></a>
  3219. <p>Warn for obsolescent usages, according to the C Standard, in a
  3220. declaration. For example, warn if storage-class specifiers like
  3221. <code>static</code> are not the first things in a declaration. This warning
  3222. is also enabled by <samp>-Wextra</samp>.
  3223. </p>
  3224. </dd>
  3225. <dt><code>-Wold-style-definition <span class="roman">(C and Objective-C only)</span></code></dt>
  3226. <dd><a name="index-Wold_002dstyle_002ddefinition"></a>
  3227. <a name="index-Wno_002dold_002dstyle_002ddefinition"></a>
  3228. <p>Warn if an old-style function definition is used. A warning is given
  3229. even if there is a previous prototype. A definition using &lsquo;<samp>()</samp>&rsquo;
  3230. is not considered an old-style definition in C2X mode, because it is
  3231. equivalent to &lsquo;<samp>(void)</samp>&rsquo; in that case, but is considered an
  3232. old-style definition for older standards.
  3233. </p>
  3234. </dd>
  3235. <dt><code>-Wmissing-parameter-type <span class="roman">(C and Objective-C only)</span></code></dt>
  3236. <dd><a name="index-Wmissing_002dparameter_002dtype"></a>
  3237. <a name="index-Wno_002dmissing_002dparameter_002dtype"></a>
  3238. <p>A function parameter is declared without a type specifier in K&amp;R-style
  3239. functions:
  3240. </p>
  3241. <div class="smallexample">
  3242. <pre class="smallexample">void foo(bar) { }
  3243. </pre></div>
  3244. <p>This warning is also enabled by <samp>-Wextra</samp>.
  3245. </p>
  3246. </dd>
  3247. <dt><code>-Wmissing-prototypes <span class="roman">(C and Objective-C only)</span></code></dt>
  3248. <dd><a name="index-Wmissing_002dprototypes"></a>
  3249. <a name="index-Wno_002dmissing_002dprototypes"></a>
  3250. <p>Warn if a global function is defined without a previous prototype
  3251. declaration. This warning is issued even if the definition itself
  3252. provides a prototype. Use this option to detect global functions
  3253. that do not have a matching prototype declaration in a header file.
  3254. This option is not valid for C++ because all function declarations
  3255. provide prototypes and a non-matching declaration declares an
  3256. overload rather than conflict with an earlier declaration.
  3257. Use <samp>-Wmissing-declarations</samp> to detect missing declarations in C++.
  3258. </p>
  3259. </dd>
  3260. <dt><code>-Wmissing-declarations</code></dt>
  3261. <dd><a name="index-Wmissing_002ddeclarations"></a>
  3262. <a name="index-Wno_002dmissing_002ddeclarations"></a>
  3263. <p>Warn if a global function is defined without a previous declaration.
  3264. Do so even if the definition itself provides a prototype.
  3265. Use this option to detect global functions that are not declared in
  3266. header files. In C, no warnings are issued for functions with previous
  3267. non-prototype declarations; use <samp>-Wmissing-prototypes</samp> to detect
  3268. missing prototypes. In C++, no warnings are issued for function templates,
  3269. or for inline functions, or for functions in anonymous namespaces.
  3270. </p>
  3271. </dd>
  3272. <dt><code>-Wmissing-field-initializers</code></dt>
  3273. <dd><a name="index-Wmissing_002dfield_002dinitializers"></a>
  3274. <a name="index-Wno_002dmissing_002dfield_002dinitializers"></a>
  3275. <a name="index-W-1"></a>
  3276. <a name="index-Wextra-1"></a>
  3277. <a name="index-Wno_002dextra-1"></a>
  3278. <p>Warn if a structure&rsquo;s initializer has some fields missing. For
  3279. example, the following code causes such a warning, because
  3280. <code>x.h</code> is implicitly zero:
  3281. </p>
  3282. <div class="smallexample">
  3283. <pre class="smallexample">struct s { int f, g, h; };
  3284. struct s x = { 3, 4 };
  3285. </pre></div>
  3286. <p>This option does not warn about designated initializers, so the following
  3287. modification does not trigger a warning:
  3288. </p>
  3289. <div class="smallexample">
  3290. <pre class="smallexample">struct s { int f, g, h; };
  3291. struct s x = { .f = 3, .g = 4 };
  3292. </pre></div>
  3293. <p>In C this option does not warn about the universal zero initializer
  3294. &lsquo;<samp>{ 0 }</samp>&rsquo;:
  3295. </p>
  3296. <div class="smallexample">
  3297. <pre class="smallexample">struct s { int f, g, h; };
  3298. struct s x = { 0 };
  3299. </pre></div>
  3300. <p>Likewise, in C++ this option does not warn about the empty { }
  3301. initializer, for example:
  3302. </p>
  3303. <div class="smallexample">
  3304. <pre class="smallexample">struct s { int f, g, h; };
  3305. s x = { };
  3306. </pre></div>
  3307. <p>This warning is included in <samp>-Wextra</samp>. To get other <samp>-Wextra</samp>
  3308. warnings without this one, use <samp>-Wextra -Wno-missing-field-initializers</samp>.
  3309. </p>
  3310. </dd>
  3311. <dt><code>-Wno-multichar</code></dt>
  3312. <dd><a name="index-Wno_002dmultichar"></a>
  3313. <a name="index-Wmultichar"></a>
  3314. <p>Do not warn if a multicharacter constant (&lsquo;<samp>'FOOF'</samp>&rsquo;) is used.
  3315. Usually they indicate a typo in the user&rsquo;s code, as they have
  3316. implementation-defined values, and should not be used in portable code.
  3317. </p>
  3318. </dd>
  3319. <dt><code>-Wnormalized=<span class="roman">[</span>none<span class="roman">|</span>id<span class="roman">|</span>nfc<span class="roman">|</span>nfkc<span class="roman">]</span></code></dt>
  3320. <dd><a name="index-Wnormalized_003d"></a>
  3321. <a name="index-Wnormalized"></a>
  3322. <a name="index-Wno_002dnormalized"></a>
  3323. <a name="index-NFC"></a>
  3324. <a name="index-NFKC"></a>
  3325. <a name="index-character-set_002c-input-normalization"></a>
  3326. <p>In ISO C and ISO C++, two identifiers are different if they are
  3327. different sequences of characters. However, sometimes when characters
  3328. outside the basic ASCII character set are used, you can have two
  3329. different character sequences that look the same. To avoid confusion,
  3330. the ISO 10646 standard sets out some <em>normalization rules</em> which
  3331. when applied ensure that two sequences that look the same are turned into
  3332. the same sequence. GCC can warn you if you are using identifiers that
  3333. have not been normalized; this option controls that warning.
  3334. </p>
  3335. <p>There are four levels of warning supported by GCC. The default is
  3336. <samp>-Wnormalized=nfc</samp>, which warns about any identifier that is
  3337. not in the ISO 10646 &ldquo;C&rdquo; normalized form, <em>NFC</em>. NFC is the
  3338. recommended form for most uses. It is equivalent to
  3339. <samp>-Wnormalized</samp>.
  3340. </p>
  3341. <p>Unfortunately, there are some characters allowed in identifiers by
  3342. ISO C and ISO C++ that, when turned into NFC, are not allowed in
  3343. identifiers. That is, there&rsquo;s no way to use these symbols in portable
  3344. ISO C or C++ and have all your identifiers in NFC.
  3345. <samp>-Wnormalized=id</samp> suppresses the warning for these characters.
  3346. It is hoped that future versions of the standards involved will correct
  3347. this, which is why this option is not the default.
  3348. </p>
  3349. <p>You can switch the warning off for all characters by writing
  3350. <samp>-Wnormalized=none</samp> or <samp>-Wno-normalized</samp>. You should
  3351. only do this if you are using some other normalization scheme (like
  3352. &ldquo;D&rdquo;), because otherwise you can easily create bugs that are
  3353. literally impossible to see.
  3354. </p>
  3355. <p>Some characters in ISO 10646 have distinct meanings but look identical
  3356. in some fonts or display methodologies, especially once formatting has
  3357. been applied. For instance <code>\u207F</code>, &ldquo;SUPERSCRIPT LATIN SMALL
  3358. LETTER N&rdquo;, displays just like a regular <code>n</code> that has been
  3359. placed in a superscript. ISO 10646 defines the <em>NFKC</em>
  3360. normalization scheme to convert all these into a standard form as
  3361. well, and GCC warns if your code is not in NFKC if you use
  3362. <samp>-Wnormalized=nfkc</samp>. This warning is comparable to warning
  3363. about every identifier that contains the letter O because it might be
  3364. confused with the digit 0, and so is not the default, but may be
  3365. useful as a local coding convention if the programming environment
  3366. cannot be fixed to display these characters distinctly.
  3367. </p>
  3368. </dd>
  3369. <dt><code>-Wno-attribute-warning</code></dt>
  3370. <dd><a name="index-Wno_002dattribute_002dwarning"></a>
  3371. <a name="index-Wattribute_002dwarning"></a>
  3372. <p>Do not warn about usage of functions (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>)
  3373. declared with <code>warning</code> attribute. By default, this warning is
  3374. enabled. <samp>-Wno-attribute-warning</samp> can be used to disable the
  3375. warning or <samp>-Wno-error=attribute-warning</samp> can be used to
  3376. disable the error when compiled with <samp>-Werror</samp> flag.
  3377. </p>
  3378. </dd>
  3379. <dt><code>-Wno-deprecated</code></dt>
  3380. <dd><a name="index-Wno_002ddeprecated"></a>
  3381. <a name="index-Wdeprecated"></a>
  3382. <p>Do not warn about usage of deprecated features. See <a href="Deprecated-Features.html#Deprecated-Features">Deprecated Features</a>.
  3383. </p>
  3384. </dd>
  3385. <dt><code>-Wno-deprecated-declarations</code></dt>
  3386. <dd><a name="index-Wno_002ddeprecated_002ddeclarations"></a>
  3387. <a name="index-Wdeprecated_002ddeclarations"></a>
  3388. <p>Do not warn about uses of functions (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>),
  3389. variables (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>
  3390. attribute.
  3391. </p>
  3392. </dd>
  3393. <dt><code>-Wno-overflow</code></dt>
  3394. <dd><a name="index-Wno_002doverflow"></a>
  3395. <a name="index-Woverflow"></a>
  3396. <p>Do not warn about compile-time overflow in constant expressions.
  3397. </p>
  3398. </dd>
  3399. <dt><code>-Wno-odr</code></dt>
  3400. <dd><a name="index-Wno_002dodr"></a>
  3401. <a name="index-Wodr"></a>
  3402. <p>Warn about One Definition Rule violations during link-time optimization.
  3403. Enabled by default.
  3404. </p>
  3405. </dd>
  3406. <dt><code>-Wopenmp-simd</code></dt>
  3407. <dd><a name="index-Wopenmp_002dsimd"></a>
  3408. <a name="index-Wno_002dopenmp_002dsimd"></a>
  3409. <p>Warn if the vectorizer cost model overrides the OpenMP
  3410. simd directive set by user. The <samp>-fsimd-cost-model=unlimited</samp>
  3411. option can be used to relax the cost model.
  3412. </p>
  3413. </dd>
  3414. <dt><code>-Woverride-init <span class="roman">(C and Objective-C only)</span></code></dt>
  3415. <dd><a name="index-Woverride_002dinit"></a>
  3416. <a name="index-Wno_002doverride_002dinit"></a>
  3417. <a name="index-W-2"></a>
  3418. <a name="index-Wextra-2"></a>
  3419. <a name="index-Wno_002dextra-2"></a>
  3420. <p>Warn if an initialized field without side effects is overridden when
  3421. using designated initializers (see <a href="Designated-Inits.html#Designated-Inits">Designated
  3422. Initializers</a>).
  3423. </p>
  3424. <p>This warning is included in <samp>-Wextra</samp>. To get other
  3425. <samp>-Wextra</samp> warnings without this one, use <samp>-Wextra
  3426. -Wno-override-init</samp>.
  3427. </p>
  3428. </dd>
  3429. <dt><code>-Wno-override-init-side-effects <span class="roman">(C and Objective-C only)</span></code></dt>
  3430. <dd><a name="index-Woverride_002dinit_002dside_002deffects"></a>
  3431. <a name="index-Wno_002doverride_002dinit_002dside_002deffects"></a>
  3432. <p>Do not warn if an initialized field with side effects is overridden when
  3433. using designated initializers (see <a href="Designated-Inits.html#Designated-Inits">Designated
  3434. Initializers</a>). This warning is enabled by default.
  3435. </p>
  3436. </dd>
  3437. <dt><code>-Wpacked</code></dt>
  3438. <dd><a name="index-Wpacked"></a>
  3439. <a name="index-Wno_002dpacked"></a>
  3440. <p>Warn if a structure is given the packed attribute, but the packed
  3441. attribute has no effect on the layout or size of the structure.
  3442. Such structures may be mis-aligned for little benefit. For
  3443. instance, in this code, the variable <code>f.x</code> in <code>struct bar</code>
  3444. is misaligned even though <code>struct bar</code> does not itself
  3445. have the packed attribute:
  3446. </p>
  3447. <div class="smallexample">
  3448. <pre class="smallexample">struct foo {
  3449. int x;
  3450. char a, b, c, d;
  3451. } __attribute__((packed));
  3452. struct bar {
  3453. char z;
  3454. struct foo f;
  3455. };
  3456. </pre></div>
  3457. </dd>
  3458. <dt><code>-Wnopacked-bitfield-compat</code></dt>
  3459. <dd><a name="index-Wpacked_002dbitfield_002dcompat"></a>
  3460. <a name="index-Wno_002dpacked_002dbitfield_002dcompat"></a>
  3461. <p>The 4.1, 4.2 and 4.3 series of GCC ignore the <code>packed</code> attribute
  3462. on bit-fields of type <code>char</code>. This was fixed in GCC 4.4 but
  3463. the change can lead to differences in the structure layout. GCC
  3464. informs you when the offset of such a field has changed in GCC 4.4.
  3465. For example there is no longer a 4-bit padding between field <code>a</code>
  3466. and <code>b</code> in this structure:
  3467. </p>
  3468. <div class="smallexample">
  3469. <pre class="smallexample">struct foo
  3470. {
  3471. char a:4;
  3472. char b:8;
  3473. } __attribute__ ((packed));
  3474. </pre></div>
  3475. <p>This warning is enabled by default. Use
  3476. <samp>-Wno-packed-bitfield-compat</samp> to disable this warning.
  3477. </p>
  3478. </dd>
  3479. <dt><code>-Wpacked-not-aligned <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  3480. <dd><a name="index-Wpacked_002dnot_002daligned"></a>
  3481. <a name="index-Wno_002dpacked_002dnot_002daligned"></a>
  3482. <p>Warn if a structure field with explicitly specified alignment in a
  3483. packed struct or union is misaligned. For example, a warning will
  3484. be issued on <code>struct S</code>, like, <code>warning: alignment 1 of
  3485. 'struct S' is less than 8</code>, in this code:
  3486. </p>
  3487. <div class="smallexample">
  3488. <pre class="smallexample">struct __attribute__ ((aligned (8))) S8 { char a[8]; };
  3489. struct __attribute__ ((packed)) S {
  3490. struct S8 s8;
  3491. };
  3492. </pre></div>
  3493. <p>This warning is enabled by <samp>-Wall</samp>.
  3494. </p>
  3495. </dd>
  3496. <dt><code>-Wpadded</code></dt>
  3497. <dd><a name="index-Wpadded"></a>
  3498. <a name="index-Wno_002dpadded"></a>
  3499. <p>Warn if padding is included in a structure, either to align an element
  3500. of the structure or to align the whole structure. Sometimes when this
  3501. happens it is possible to rearrange the fields of the structure to
  3502. reduce the padding and so make the structure smaller.
  3503. </p>
  3504. </dd>
  3505. <dt><code>-Wredundant-decls</code></dt>
  3506. <dd><a name="index-Wredundant_002ddecls"></a>
  3507. <a name="index-Wno_002dredundant_002ddecls"></a>
  3508. <p>Warn if anything is declared more than once in the same scope, even in
  3509. cases where multiple declaration is valid and changes nothing.
  3510. </p>
  3511. </dd>
  3512. <dt><code>-Wrestrict</code></dt>
  3513. <dd><a name="index-Wrestrict"></a>
  3514. <a name="index-Wno_002drestrict"></a>
  3515. <p>Warn when an object referenced by a <code>restrict</code>-qualified parameter
  3516. (or, in C++, a <code>__restrict</code>-qualified parameter) is aliased by another
  3517. argument, or when copies between such objects overlap. For example,
  3518. the call to the <code>strcpy</code> function below attempts to truncate the string
  3519. by replacing its initial characters with the last four. However, because
  3520. the call writes the terminating NUL into <code>a[4]</code>, the copies overlap and
  3521. the call is diagnosed.
  3522. </p>
  3523. <div class="smallexample">
  3524. <pre class="smallexample">void foo (void)
  3525. {
  3526. char a[] = &quot;abcd1234&quot;;
  3527. strcpy (a, a + 4);
  3528. &hellip;
  3529. }
  3530. </pre></div>
  3531. <p>The <samp>-Wrestrict</samp> option detects some instances of simple overlap
  3532. even without optimization but works best at <samp>-O2</samp> and above. It
  3533. is included in <samp>-Wall</samp>.
  3534. </p>
  3535. </dd>
  3536. <dt><code>-Wnested-externs <span class="roman">(C and Objective-C only)</span></code></dt>
  3537. <dd><a name="index-Wnested_002dexterns"></a>
  3538. <a name="index-Wno_002dnested_002dexterns"></a>
  3539. <p>Warn if an <code>extern</code> declaration is encountered within a function.
  3540. </p>
  3541. </dd>
  3542. <dt><code>-Winline</code></dt>
  3543. <dd><a name="index-Winline"></a>
  3544. <a name="index-Wno_002dinline"></a>
  3545. <p>Warn if a function that is declared as inline cannot be inlined.
  3546. Even with this option, the compiler does not warn about failures to
  3547. inline functions declared in system headers.
  3548. </p>
  3549. <p>The compiler uses a variety of heuristics to determine whether or not
  3550. to inline a function. For example, the compiler takes into account
  3551. the size of the function being inlined and the amount of inlining
  3552. that has already been done in the current function. Therefore,
  3553. seemingly insignificant changes in the source program can cause the
  3554. warnings produced by <samp>-Winline</samp> to appear or disappear.
  3555. </p>
  3556. </dd>
  3557. <dt><code>-Wint-in-bool-context</code></dt>
  3558. <dd><a name="index-Wint_002din_002dbool_002dcontext"></a>
  3559. <a name="index-Wno_002dint_002din_002dbool_002dcontext"></a>
  3560. <p>Warn for suspicious use of integer values where boolean values are expected,
  3561. such as conditional expressions (?:) using non-boolean integer constants in
  3562. boolean context, like <code>if (a &lt;= b ? 2 : 3)</code>. Or left shifting of signed
  3563. integers in boolean context, like <code>for (a = 0; 1 &lt;&lt; a; a++);</code>. Likewise
  3564. for all kinds of multiplications regardless of the data type.
  3565. This warning is enabled by <samp>-Wall</samp>.
  3566. </p>
  3567. </dd>
  3568. <dt><code>-Wno-int-to-pointer-cast</code></dt>
  3569. <dd><a name="index-Wno_002dint_002dto_002dpointer_002dcast"></a>
  3570. <a name="index-Wint_002dto_002dpointer_002dcast"></a>
  3571. <p>Suppress warnings from casts to pointer type of an integer of a
  3572. different size. In C++, casting to a pointer type of smaller size is
  3573. an error. <samp>Wint-to-pointer-cast</samp> is enabled by default.
  3574. </p>
  3575. </dd>
  3576. <dt><code>-Wno-pointer-to-int-cast <span class="roman">(C and Objective-C only)</span></code></dt>
  3577. <dd><a name="index-Wno_002dpointer_002dto_002dint_002dcast"></a>
  3578. <a name="index-Wpointer_002dto_002dint_002dcast"></a>
  3579. <p>Suppress warnings from casts from a pointer to an integer type of a
  3580. different size.
  3581. </p>
  3582. </dd>
  3583. <dt><code>-Winvalid-pch</code></dt>
  3584. <dd><a name="index-Winvalid_002dpch"></a>
  3585. <a name="index-Wno_002dinvalid_002dpch"></a>
  3586. <p>Warn if a precompiled header (see <a href="Precompiled-Headers.html#Precompiled-Headers">Precompiled Headers</a>) is found in
  3587. the search path but cannot be used.
  3588. </p>
  3589. </dd>
  3590. <dt><code>-Wlong-long</code></dt>
  3591. <dd><a name="index-Wlong_002dlong"></a>
  3592. <a name="index-Wno_002dlong_002dlong"></a>
  3593. <p>Warn if <code>long long</code> type is used. This is enabled by either
  3594. <samp>-Wpedantic</samp> or <samp>-Wtraditional</samp> in ISO C90 and C++98
  3595. modes. To inhibit the warning messages, use <samp>-Wno-long-long</samp>.
  3596. </p>
  3597. </dd>
  3598. <dt><code>-Wvariadic-macros</code></dt>
  3599. <dd><a name="index-Wvariadic_002dmacros"></a>
  3600. <a name="index-Wno_002dvariadic_002dmacros"></a>
  3601. <p>Warn if variadic macros are used in ISO C90 mode, or if the GNU
  3602. alternate syntax is used in ISO C99 mode. This is enabled by either
  3603. <samp>-Wpedantic</samp> or <samp>-Wtraditional</samp>. To inhibit the warning
  3604. messages, use <samp>-Wno-variadic-macros</samp>.
  3605. </p>
  3606. </dd>
  3607. <dt><code>-Wno-varargs</code></dt>
  3608. <dd><a name="index-Wvarargs"></a>
  3609. <a name="index-Wno_002dvarargs"></a>
  3610. <p>Do not warn upon questionable usage of the macros used to handle variable
  3611. arguments like <code>va_start</code>. These warnings are enabled by default.
  3612. </p>
  3613. </dd>
  3614. <dt><code>-Wvector-operation-performance</code></dt>
  3615. <dd><a name="index-Wvector_002doperation_002dperformance"></a>
  3616. <a name="index-Wno_002dvector_002doperation_002dperformance"></a>
  3617. <p>Warn if vector operation is not implemented via SIMD capabilities of the
  3618. architecture. Mainly useful for the performance tuning.
  3619. Vector operation can be implemented <code>piecewise</code>, which means that the
  3620. scalar operation is performed on every vector element;
  3621. <code>in parallel</code>, which means that the vector operation is implemented
  3622. using scalars of wider type, which normally is more performance efficient;
  3623. and <code>as a single scalar</code>, which means that vector fits into a
  3624. scalar type.
  3625. </p>
  3626. </dd>
  3627. <dt><code>-Wvla</code></dt>
  3628. <dd><a name="index-Wvla"></a>
  3629. <a name="index-Wno_002dvla"></a>
  3630. <p>Warn if a variable-length array is used in the code.
  3631. <samp>-Wno-vla</samp> prevents the <samp>-Wpedantic</samp> warning of
  3632. the variable-length array.
  3633. </p>
  3634. </dd>
  3635. <dt><code>-Wvla-larger-than=<var>byte-size</var></code></dt>
  3636. <dd><a name="index-Wvla_002dlarger_002dthan_003d"></a>
  3637. <a name="index-Wno_002dvla_002dlarger_002dthan"></a>
  3638. <p>If this option is used, the compiler warns for declarations of
  3639. variable-length arrays whose size is either unbounded, or bounded
  3640. by an argument that allows the array size to exceed <var>byte-size</var>
  3641. bytes. This is similar to how <samp>-Walloca-larger-than=</samp><var>byte-size</var>
  3642. works, but with variable-length arrays.
  3643. </p>
  3644. <p>Note that GCC may optimize small variable-length arrays of a known
  3645. value into plain arrays, so this warning may not get triggered for
  3646. such arrays.
  3647. </p>
  3648. <p><samp>-Wvla-larger-than=</samp>&lsquo;<samp>PTRDIFF_MAX</samp>&rsquo; is enabled by default but
  3649. is typically only effective when <samp>-ftree-vrp</samp> is active (default
  3650. for <samp>-O2</samp> and above).
  3651. </p>
  3652. <p>See also <samp>-Walloca-larger-than=<var>byte-size</var></samp>.
  3653. </p>
  3654. </dd>
  3655. <dt><code>-Wno-vla-larger-than</code></dt>
  3656. <dd><a name="index-Wno_002dvla_002dlarger_002dthan-1"></a>
  3657. <p>Disable <samp>-Wvla-larger-than=</samp> warnings. The option is equivalent
  3658. to <samp>-Wvla-larger-than=</samp>&lsquo;<samp>SIZE_MAX</samp>&rsquo; or larger.
  3659. </p>
  3660. </dd>
  3661. <dt><code>-Wvolatile-register-var</code></dt>
  3662. <dd><a name="index-Wvolatile_002dregister_002dvar"></a>
  3663. <a name="index-Wno_002dvolatile_002dregister_002dvar"></a>
  3664. <p>Warn if a register variable is declared volatile. The volatile
  3665. modifier does not inhibit all optimizations that may eliminate reads
  3666. and/or writes to register variables. This warning is enabled by
  3667. <samp>-Wall</samp>.
  3668. </p>
  3669. </dd>
  3670. <dt><code>-Wdisabled-optimization</code></dt>
  3671. <dd><a name="index-Wdisabled_002doptimization"></a>
  3672. <a name="index-Wno_002ddisabled_002doptimization"></a>
  3673. <p>Warn if a requested optimization pass is disabled. This warning does
  3674. not generally indicate that there is anything wrong with your code; it
  3675. merely indicates that GCC&rsquo;s optimizers are unable to handle the code
  3676. effectively. Often, the problem is that your code is too big or too
  3677. complex; GCC refuses to optimize programs when the optimization
  3678. itself is likely to take inordinate amounts of time.
  3679. </p>
  3680. </dd>
  3681. <dt><code>-Wpointer-sign <span class="roman">(C and Objective-C only)</span></code></dt>
  3682. <dd><a name="index-Wpointer_002dsign"></a>
  3683. <a name="index-Wno_002dpointer_002dsign"></a>
  3684. <p>Warn for pointer argument passing or assignment with different signedness.
  3685. This option is only supported for C and Objective-C. It is implied by
  3686. <samp>-Wall</samp> and by <samp>-Wpedantic</samp>, which can be disabled with
  3687. <samp>-Wno-pointer-sign</samp>.
  3688. </p>
  3689. </dd>
  3690. <dt><code>-Wstack-protector</code></dt>
  3691. <dd><a name="index-Wstack_002dprotector"></a>
  3692. <a name="index-Wno_002dstack_002dprotector"></a>
  3693. <p>This option is only active when <samp>-fstack-protector</samp> is active. It
  3694. warns about functions that are not protected against stack smashing.
  3695. </p>
  3696. </dd>
  3697. <dt><code>-Woverlength-strings</code></dt>
  3698. <dd><a name="index-Woverlength_002dstrings"></a>
  3699. <a name="index-Wno_002doverlength_002dstrings"></a>
  3700. <p>Warn about string constants that are longer than the &ldquo;minimum
  3701. maximum&rdquo; length specified in the C standard. Modern compilers
  3702. generally allow string constants that are much longer than the
  3703. standard&rsquo;s minimum limit, but very portable programs should avoid
  3704. using longer strings.
  3705. </p>
  3706. <p>The limit applies <em>after</em> string constant concatenation, and does
  3707. not count the trailing NUL. In C90, the limit was 509 characters; in
  3708. C99, it was raised to 4095. C++98 does not specify a normative
  3709. minimum maximum, so we do not diagnose overlength strings in C++.
  3710. </p>
  3711. <p>This option is implied by <samp>-Wpedantic</samp>, and can be disabled with
  3712. <samp>-Wno-overlength-strings</samp>.
  3713. </p>
  3714. </dd>
  3715. <dt><code>-Wunsuffixed-float-constants <span class="roman">(C and Objective-C only)</span></code></dt>
  3716. <dd><a name="index-Wunsuffixed_002dfloat_002dconstants"></a>
  3717. <a name="index-Wno_002dunsuffixed_002dfloat_002dconstants"></a>
  3718. <p>Issue a warning for any floating constant that does not have
  3719. a suffix. When used together with <samp>-Wsystem-headers</samp> it
  3720. warns about such constants in system header files. This can be useful
  3721. when preparing code to use with the <code>FLOAT_CONST_DECIMAL64</code> pragma
  3722. from the decimal floating-point extension to C99.
  3723. </p>
  3724. </dd>
  3725. <dt><code>-Wno-lto-type-mismatch</code></dt>
  3726. <dd><a name="index-Wlto_002dtype_002dmismatch"></a>
  3727. <a name="index-Wno_002dlto_002dtype_002dmismatch"></a>
  3728. <p>During the link-time optimization, do not warn about type mismatches in
  3729. global declarations from different compilation units.
  3730. Requires <samp>-flto</samp> to be enabled. Enabled by default.
  3731. </p>
  3732. </dd>
  3733. <dt><code>-Wno-designated-init <span class="roman">(C and Objective-C only)</span></code></dt>
  3734. <dd><a name="index-Wdesignated_002dinit"></a>
  3735. <a name="index-Wno_002ddesignated_002dinit"></a>
  3736. <p>Suppress warnings when a positional initializer is used to initialize
  3737. a structure that has been marked with the <code>designated_init</code>
  3738. attribute.
  3739. </p>
  3740. </dd>
  3741. <dt><code>-Wno-hsa</code></dt>
  3742. <dd><a name="index-Whsa"></a>
  3743. <a name="index-Wno_002dhsa"></a>
  3744. <p>Do not warn when HSAIL cannot be emitted for the compiled function or
  3745. OpenMP construct. These warnings are enabled by default.
  3746. </p>
  3747. </dd>
  3748. </dl>
  3749. <hr>
  3750. <div class="header">
  3751. <p>
  3752. Next: <a href="Static-Analyzer-Options.html#Static-Analyzer-Options" accesskey="n" rel="next">Static Analyzer Options</a>, Previous: <a href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" accesskey="p" rel="prev">Diagnostic Message Formatting Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  3753. </div>
  3754. </body>
  3755. </html>