]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gcc/gcc-command-options/options-to-request-or-suppress-warnings.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gcc / gcc-command-options / options-to-request-or-suppress-warnings.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: options to control warnings, warning messages, messages, warning, suppressing warnings
7
8.. _warning-options:
9
10Options to Request or Suppress Warnings
11***************************************
12
13Warnings are diagnostic messages that report constructions that
14are not inherently erroneous but that are risky or suggest there
15may have been an error.
16
17The following language-independent options do not enable specific
18warnings but control the kinds of diagnostics produced by GCC.
19
20.. index:: syntax checking
21
22.. option:: -fsyntax-only
23
24 Check the code for syntax errors, but don't do anything beyond that.
25
26.. option:: -fmax-errors={n}
27
28 Limits the maximum number of error messages to :samp:`{n}`, at which point
29 GCC bails out rather than attempting to continue processing the source
30 code. If :samp:`{n}` is 0 (the default), there is no limit on the number
31 of error messages produced. If :option:`-Wfatal-errors` is also
32 specified, then :option:`-Wfatal-errors` takes precedence over this
33 option.
34
35.. option:: -w
36
37 Inhibit all warning messages.
38
39.. option:: -Werror
40
41 Make all warnings into errors.
42
43.. option:: -Wno-error
44
45 Default setting; overrides :option:`-Werror`.
46
47.. option:: -Werror=
48
49 Make the specified warning into an error. The specifier for a warning
50 is appended; for example :option:`-Werror=switch` turns the warnings
51 controlled by :option:`-Wswitch` into errors. This switch takes a
52 negative form, to be used to negate :option:`-Werror` for specific
53 warnings; for example :option:`-Wno-error=switch` makes
54 :option:`-Wswitch` warnings not be errors, even when :option:`-Werror`
55 is in effect.
56
57 The warning message for each controllable warning includes the
58 option that controls the warning. That option can then be used with
59 :option:`-Werror=` and :option:`-Wno-error=` as described above.
60 (Printing of the option in the warning message can be disabled using the
61 :option:`-fno-diagnostics-show-option` flag.)
62
63 Note that specifying :option:`-Werror=foo` automatically implies
64 :option:`-Wfoo`. However, :option:`-Wno-error=foo` does not
65 imply anything.
66
67.. option:: -Wno-error=
68
69 Default setting; overrides :option:`-Werror=`.
70
71.. option:: -Wfatal-errors
72
73 This option causes the compiler to abort compilation on the first error
74 occurred rather than trying to keep going and printing further error
75 messages.
76
77.. option:: -Wno-fatal-errors
78
79 Default setting; overrides :option:`-Wfatal-errors`.
80
81You can request many specific warnings with options beginning with
82:samp:`-W`, for example :option:`-Wimplicit` to request warnings on
83implicit declarations. Each of these specific warning options also
84has a negative form beginning :samp:`-Wno-` to turn off warnings; for
85example, :option:`-Wno-implicit`. This manual lists only one of the
86two forms, whichever is not the default. For further
87language-specific options also refer to :ref:`c++-dialect-options` and
88:ref:`objective-c-and-objective-c++-dialect-options`.
89Additional warnings can be produced by enabling the static analyzer;
90See :ref:`static-analyzer-options`.
91
92Some options, such as :option:`-Wall` and :option:`-Wextra`, turn on other
93options, such as :option:`-Wunused`, which may turn on further options,
94such as :option:`-Wunused-value`. The combined effect of positive and
95negative forms is that more specific options have priority over less
96specific ones, independently of their position in the command-line. For
97options of the same specificity, the last one takes effect. Options
98enabled or disabled via pragmas (see :ref:`diagnostic-pragmas`) take effect
99as if they appeared at the end of the command-line.
100
101When an unrecognized warning option is requested (e.g.,
102:option:`-Wunknown-warning`), GCC emits a diagnostic stating
103that the option is not recognized. However, if the :option:`-Wno-` form
104is used, the behavior is slightly different: no diagnostic is
105produced for :option:`-Wno-unknown-warning` unless other diagnostics
106are being produced. This allows the use of new :option:`-Wno-` options
107with old compilers, but if something goes wrong, the compiler
108warns that an unrecognized option is present.
109
110The effectiveness of some warnings depends on optimizations also being
111enabled. For example :option:`-Wsuggest-final-types` is more effective
112with link-time optimization and some instances of other warnings may
113not be issued at all unless optimization is enabled. While optimization
114in general improves the efficacy of control and data flow sensitive
115warnings, in some cases it may also cause false positives.
116
117.. option:: -Wpedantic, -pedantic
118
119 Issue all the warnings demanded by strict ISO C and ISO C++;
120 reject all programs that use forbidden extensions, and some other
121 programs that do not follow ISO C and ISO C++. For ISO C, follows the
122 version of the ISO C standard specified by any :option:`-std` option used.
123
124 Valid ISO C and ISO C++ programs should compile properly with or without
125 this option (though a rare few require :option:`-ansi` or a
126 :option:`-std` option specifying the required version of ISO C). However,
127 without this option, certain GNU extensions and traditional C and C++
128 features are supported as well. With this option, they are rejected.
129
130 :option:`-Wpedantic` does not cause warning messages for use of the
131 alternate keywords whose names begin and end with :samp:`__`. This alternate
132 format can also be used to disable warnings for non-ISO :samp:`__intN` types,
133 i.e. :samp:`__intN__`.
134 Pedantic warnings are also disabled in the expression that follows
135 ``__extension__``. However, only system header files should use
136 these escape routes; application programs should avoid them.
137 See :ref:`alternate-keywords`.
138
139 Some users try to use :option:`-Wpedantic` to check programs for strict ISO
140 C conformance. They soon find that it does not do quite what they want:
141 it finds some non-ISO practices, but not all---only those for which
142 ISO C *requires* a diagnostic, and some others for which
143 diagnostics have been added.
144
145 A feature to report any failure to conform to ISO C might be useful in
146 some instances, but would require considerable additional work and would
147 be quite different from :option:`-Wpedantic`. We don't have plans to
148 support such a feature in the near future.
149
150 Where the standard specified with :option:`-std` represents a GNU
151 extended dialect of C, such as :samp:`gnu90` or :samp:`gnu99`, there is a
152 corresponding :dfn:`base standard`, the version of ISO C on which the GNU
153 extended dialect is based. Warnings from :option:`-Wpedantic` are given
154 where they are required by the base standard. (It does not make sense
155 for such warnings to be given only for features not in the specified GNU
156 C dialect, since by definition the GNU dialects of C include all
157 features the compiler supports with the given option, and there would be
158 nothing to warn about.)
159
160.. option:: -Wno-pedantic
161
162 Default setting; overrides :option:`-Wpedantic`.
163
164.. option:: -pedantic-errors
165
166 Give an error whenever the :dfn:`base standard` (see :option:`-Wpedantic`)
167 requires a diagnostic, in some cases where there is undefined behavior
168 at compile-time and in some other cases that do not prevent compilation
169 of programs that are valid according to the standard. This is not
170 equivalent to :option:`-Werror=pedantic`, since there are errors enabled
171 by this option and not enabled by the latter and vice versa.
172
173.. option:: -Wall
174
175 This enables all the warnings about constructions that some users
176 consider questionable, and that are easy to avoid (or modify to
177 prevent the warning), even in conjunction with macros. This also
178 enables some language-specific warnings described in :ref:`c++-dialect-options` and :ref:`objective-c-and-objective-c++-dialect-options`.
179
180 :option:`-Wall` turns on the following warning flags:
181
182 :option:`-Waddress` |gol|
183 :option:`-Warray-bounds=1` (only with :option:`-O2` ) |gol|
184 :option:`-Warray-compare` |gol|
185 :option:`-Warray-parameter=2` (C and Objective :option:`-C` only) |gol|
186 :option:`-Wbool-compare` |gol|
187 :option:`-Wbool-operation` |gol|
188 :option:`-Wc++11-compat` :option:`-Wc++14-compat` |gol|
189 :option:`-Wcatch-value` (C++ and Objective :option:`-C++` only) |gol|
190 :option:`-Wchar-subscripts` |gol|
191 :option:`-Wcomment` |gol|
192 :option:`-Wdangling-pointer=2` |gol|
193 :option:`-Wduplicate-decl-specifier` (C and Objective :option:`-C` only) |gol|
194 :option:`-Wenum-compare` (in C/ObjC; this is on by default in C++) |gol|
195 :option:`-Wenum-int-mismatch` (C and Objective :option:`-C` only) |gol|
196 :option:`-Wformat` |gol|
197 :option:`-Wformat-overflow` |gol|
198 :option:`-Wformat-truncation` |gol|
199 :option:`-Wint-in-bool-context` |gol|
200 :option:`-Wimplicit` (C and Objective :option:`-C` only) |gol|
201 :option:`-Wimplicit-int` (C and Objective :option:`-C` only) |gol|
202 :option:`-Wimplicit-function-declaration` (C and Objective :option:`-C` only) |gol|
203 :option:`-Winit-self` (only for C++) |gol|
204 :option:`-Wlogical-not-parentheses` |gol|
205 :option:`-Wmain` (only for C/ObjC and unless :option:`-ffreestanding` ) |gol|
206 :option:`-Wmaybe-uninitialized` |gol|
207 :option:`-Wmemset-elt-size` |gol|
208 :option:`-Wmemset-transposed-args` |gol|
209 :option:`-Wmisleading-indentation` (only for C/C++) |gol|
210 :option:`-Wmismatched-dealloc` |gol|
211 :option:`-Wmismatched-new-delete` (only for C/C++) |gol|
212 :option:`-Wmissing-attributes` |gol|
213 :option:`-Wmissing-braces` (only for C/ObjC) |gol|
214 :option:`-Wmultistatement-macros` |gol|
215 :option:`-Wnarrowing` (only for C++) |gol|
216 :option:`-Wnonnull` |gol|
217 :option:`-Wnonnull-compare` |gol|
218 :option:`-Wopenmp-simd` |gol|
219 :option:`-Wparentheses` |gol|
220 :option:`-Wpessimizing-move` (only for C++) |gol|
221 :option:`-Wpointer-sign` |gol|
222 :option:`-Wrange-loop-construct` (only for C++) |gol|
223 :option:`-Wreorder` |gol|
224 :option:`-Wrestrict` |gol|
225 :option:`-Wreturn-type` |gol|
226 :option:`-Wself-move` (only for C++) |gol|
227 :option:`-Wsequence-point` |gol|
228 :option:`-Wsign-compare` (only in C++) |gol|
229 :option:`-Wsizeof-array-div` |gol|
230 :option:`-Wsizeof-pointer-div` |gol|
231 :option:`-Wsizeof-pointer-memaccess` |gol|
232 :option:`-Wstrict-aliasing` |gol|
233 :option:`-Wstrict-overflow=1` |gol|
234 :option:`-Wswitch` |gol|
235 :option:`-Wtautological-compare` |gol|
236 :option:`-Wtrigraphs` |gol|
237 :option:`-Wuninitialized` |gol|
238 :option:`-Wunknown-pragmas` |gol|
239 :option:`-Wunused-function` |gol|
240 :option:`-Wunused-label` |gol|
241 :option:`-Wunused-value` |gol|
242 :option:`-Wunused-variable` |gol|
243 :option:`-Wuse-after-free=3` |gol|
244 :option:`-Wvla-parameter` (C and Objective :option:`-C` only) |gol|
245 :option:`-Wvolatile-register-var` |gol|
246 :option:`-Wzero-length-bounds`
247
248 Note that some warning flags are not implied by :option:`-Wall`. Some of
249 them warn about constructions that users generally do not consider
250 questionable, but which occasionally you might wish to check for;
251 others warn about constructions that are necessary or hard to avoid in
252 some cases, and there is no simple way to modify the code to suppress
253 the warning. Some of them are enabled by :option:`-Wextra` but many of
254 them must be enabled individually.
255
256.. option:: -Wno-all
257
258 Default setting; overrides :option:`-Wall`.
259
260.. option:: -Wextra
261
262 This enables some extra warning flags that are not enabled by
263 :option:`-Wall`. (This option used to be called :option:`-W`. The older
264 name is still supported, but the newer name is more descriptive.)
265
266 :option:`-Wclobbered` |gol|
267 :option:`-Wcast-function-type` |gol|
268 :option:`-Wdeprecated-copy` (C++ only) |gol|
269 :option:`-Wempty-body` |gol|
270 :option:`-Wenum-conversion` (C only) |gol|
271 :option:`-Wignored-qualifiers` |gol|
272 :option:`-Wimplicit-fallthrough=3` |gol|
273 :option:`-Wmissing-field-initializers` |gol|
274 :option:`-Wmissing-parameter-type` (C only) |gol|
275 :option:`-Wold-style-declaration` (C only) |gol|
276 :option:`-Woverride-init` |gol|
277 :option:`-Wsign-compare` (C only) |gol|
278 :option:`-Wstring-compare` |gol|
279 :option:`-Wredundant-move` (only for C++) |gol|
280 :option:`-Wtype-limits` |gol|
281 :option:`-Wuninitialized` |gol|
282 :option:`-Wshift-negative-value` (in C++11 to C++17 and in C99 and newer) |gol|
283 :option:`-Wunused-parameter` (only with :option:`-Wunused` or :option:`-Wall` ) |gol|
284 :option:`-Wunused-but-set-parameter` (only with :option:`-Wunused` or :option:`-Wall` )
285 The option :option:`-Wextra` also prints warning messages for the
286 following cases:
287
288 * A pointer is compared against integer zero with ``<``, ``<=``,
289 ``>``, or ``>=``.
290
291 * (C++ only) An enumerator and a non-enumerator both appear in a
292 conditional expression.
293
294 * (C++ only) Ambiguous virtual bases.
295
296 * (C++ only) Subscripting an array that has been declared ``register``.
297
298 * (C++ only) Taking the address of a variable that has been declared
299 ``register``.
300
301 * (C++ only) A base class is not initialized in the copy constructor
302 of a derived class.
303
304.. option:: -Wno-extra
305
306 Default setting; overrides :option:`-Wextra`.
307
308.. option:: -Wabi
309
310 .. note::
311
312 C, Objective-C, C++ and Objective-C++ only
313
314 Warn about code affected by ABI changes. This includes code that may
315 not be compatible with the vendor-neutral C++ ABI as well as the psABI
316 for the particular target.
317
318 Since G++ now defaults to updating the ABI with each major release,
319 normally :option:`-Wabi` warns only about C++ ABI compatibility
320 problems if there is a check added later in a release series for an
321 ABI issue discovered since the initial release. :option:`-Wabi` warns
322 about more things if an older ABI version is selected (with
323 :option:`-fabi-version=n`).
324
325 :option:`-Wabi` can also be used with an explicit version number to
326 warn about C++ ABI compatibility with a particular :option:`-fabi-version`
327 level, e.g. :option:`-Wabi=2` to warn about changes relative to
328 :option:`-fabi-version=2`.
329
330 If an explicit version number is provided and
331 :option:`-fabi-compat-version` is not specified, the version number
332 from this option is used for compatibility aliases. If no explicit
333 version number is provided with this option, but
334 :option:`-fabi-compat-version` is specified, that version number is
335 used for C++ ABI warnings.
336
337 Although an effort has been made to warn about
338 all such cases, there are probably some cases that are not warned about,
339 even though G++ is generating incompatible code. There may also be
340 cases where warnings are emitted even though the code that is generated
341 is compatible.
342
343 You should rewrite your code to avoid these warnings if you are
344 concerned about the fact that code generated by G++ may not be binary
345 compatible with code generated by other compilers.
346
347 Known incompatibilities in :option:`-fabi-version=2` (which was the
348 default from GCC 3.4 to 4.9) include:
349
350 * A template with a non-type template parameter of reference type was
351 mangled incorrectly:
352
353 .. code-block:: c++
354
355 extern int N;
356 template <int &> struct S {};
357 void n (S<N>) {2}
358
359 This was fixed in :option:`-fabi-version=3`.
360
361 * SIMD vector types declared using ``__attribute ((vector_size))`` were
362 mangled in a non-standard way that does not allow for overloading of
363 functions taking vectors of different sizes.
364
365 The mangling was changed in :option:`-fabi-version=4`.
366
367 * ``__attribute ((const))`` and :fn-attr:`noreturn` were mangled as type
368 qualifiers, and ``decltype`` of a plain declaration was folded away.
369
370 These mangling issues were fixed in :option:`-fabi-version=5`.
371
372 * Scoped enumerators passed as arguments to a variadic function are
373 promoted like unscoped enumerators, causing ``va_arg`` to complain.
374 On most targets this does not actually affect the parameter passing
375 ABI, as there is no way to pass an argument smaller than ``int``.
376
377 Also, the ABI changed the mangling of template argument packs,
378 ``const_cast``, ``static_cast``, prefix increment/decrement, and
379 a class scope function used as a template argument.
380
381 These issues were corrected in :option:`-fabi-version=6`.
382
383 * Lambdas in default argument scope were mangled incorrectly, and the
384 ABI changed the mangling of ``nullptr_t``.
385
386 These issues were corrected in :option:`-fabi-version=7`.
387
388 * When mangling a function type with function-cv-qualifiers, the
389 un-qualified function type was incorrectly treated as a substitution
390 candidate.
391
392 This was fixed in :option:`-fabi-version=8`, the default for GCC 5.1.
393
394 * ``decltype(nullptr)`` incorrectly had an alignment of 1, leading to
395 unaligned accesses. Note that this did not affect the ABI of a
396 function with a ``nullptr_t`` parameter, as parameters have a
397 minimum alignment.
398
399 This was fixed in :option:`-fabi-version=9`, the default for GCC 5.2.
400
401 * Target-specific attributes that affect the identity of a type, such as
402 ia32 calling conventions on a function type (stdcall, regparm, etc.),
403 did not affect the mangled name, leading to name collisions when
404 function pointers were used as template arguments.
405
406 This was fixed in :option:`-fabi-version=10`, the default for GCC 6.1.
407
408 This option also enables warnings about psABI-related changes.
409 The known psABI changes at this point include:
410
411 * For SysV/x86-64, unions with ``long double`` members are
412 passed in memory as specified in psABI. Prior to GCC 4.4, this was not
413 the case. For example:
414
415 .. code-block:: c++
416
417 union U {
418 long double ld;
419 int i;
420 };
421
422 ``union U`` is now always passed in memory.
423
424.. option:: -Wno-abi
425
426 Default setting; overrides :option:`-Wabi`.
427
428.. option:: -Wchar-subscripts
429
430 Warn if an array subscript has type ``char``. This is a common cause
431 of error, as programmers often forget that this type is signed on some
432 machines.
433 This warning is enabled by :option:`-Wall`.
434
435.. option:: -Wno-char-subscripts
436
437 Default setting; overrides :option:`-Wchar-subscripts`.
438
439.. option:: -Wno-coverage-mismatch
440
441 Warn if feedback profiles do not match when using the
442 :option:`-fprofile-use` option.
443 If a source file is changed between compiling with :option:`-fprofile-generate`
444 and with :option:`-fprofile-use`, the files with the profile feedback can fail
445 to match the source file and GCC cannot use the profile feedback
446 information. By default, this warning is enabled and is treated as an
447 error. :option:`-Wno-coverage-mismatch` can be used to disable the
448 warning or :option:`-Wno-error=coverage-mismatch` can be used to
449 disable the error. Disabling the error for this warning can result in
450 poorly optimized code and is useful only in the
451 case of very minor changes such as bug fixes to an existing code-base.
452 Completely disabling the warning is not recommended.
453
454.. option:: -Wcoverage-mismatch
455
456 Default setting; overrides :option:`-Wno-coverage-mismatch`.
457
458.. option:: -Wno-coverage-invalid-line-number
459
460 Warn in case a function ends earlier than it begins due
461 to an invalid linenum macros. The warning is emitted only
462 with :option:`--coverage` enabled.
463
464 By default, this warning is enabled and is treated as an
465 error. :option:`-Wno-coverage-invalid-line-number` can be used to disable the
466 warning or :option:`-Wno-error=coverage-invalid-line-number` can be used to
467 disable the error.
468
469.. option:: -Wcoverage-invalid-line-number
470
471 Default setting; overrides :option:`-Wno-coverage-invalid-line-number`.
472
473.. option:: -Wno-cpp
474
475 .. note::
476
477 C, Objective-C, C++, Objective-C++ and Fortran only
478
479 Suppress warning messages emitted by ``#warning`` directives.
480
481.. option:: -Wcpp
482
483 Default setting; overrides :option:`-Wno-cpp`.
484
485.. option:: -Wdouble-promotion
486
487 .. note::
488
489 C, C++, Objective-C and Objective-C++ only
490
491 Give a warning when a value of type ``float`` is implicitly
492 promoted to ``double``. CPUs with a 32-bit 'single-precision'
493 floating-point unit implement ``float`` in hardware, but emulate
494 ``double`` in software. On such a machine, doing computations
495 using ``double`` values is much more expensive because of the
496 overhead required for software emulation.
497
498 It is easy to accidentally do computations with ``double`` because
499 floating-point literals are implicitly of type ``double``. For
500 example, in:
501
502 .. code-block:: c++
503
504 float area(float radius)
505 {
506 return 3.14159 * radius * radius;
507 }
508
509 the compiler performs the entire computation with ``double``
510 because the floating-point literal is a ``double``.
511
512.. option:: -Wno-double-promotion
513
514 Default setting; overrides :option:`-Wdouble-promotion`.
515
516.. option:: -Wduplicate-decl-specifier
517
518 .. note::
519
520 C and Objective-C only
521
522 Warn if a declaration has duplicate ``const``, ``volatile``,
523 ``restrict`` or ``_Atomic`` specifier. This warning is enabled by
524 :option:`-Wall`.
525
526.. option:: -Wno-duplicate-decl-specifier
527
528 Default setting; overrides :option:`-Wduplicate-decl-specifier`.
529
530.. option:: -Wformat, -Wformat={n}
531
532 Check calls to ``printf`` and ``scanf``, etc., to make sure that
533 the arguments supplied have types appropriate to the format string
534 specified, and that the conversions specified in the format string make
535 sense. This includes standard functions, and others specified by format
536 attributes (see :ref:`function-attributes`), in the ``printf``,
537 ``scanf``, ``strftime`` and ``strfmon`` (an X/Open extension,
538 not in the C standard) families (or other target-specific families).
539 Which functions are checked without format attributes having been
540 specified depends on the standard version selected, and such checks of
541 functions without the attribute specified are disabled by
542 :option:`-ffreestanding` or :option:`-fno-builtin`.
543
544 The formats are checked against the format features supported by GNU
545 libc version 2.2. These include all ISO C90 and C99 features, as well
546 as features from the Single Unix Specification and some BSD and GNU
547 extensions. Other library implementations may not support all these
548 features; GCC does not support warning about features that go beyond a
549 particular library's limitations. However, if :option:`-Wpedantic` is used
550 with :option:`-Wformat`, warnings are given about format features not
551 in the selected standard version (but not for ``strfmon`` formats,
552 since those are not in any version of the C standard). See :ref:`c-dialect-options`.
553
554 .. option:: -Wformat=1
555
556 Option :option:`-Wformat` is equivalent to :option:`-Wformat=1`, and
557 :option:`-Wno-format` is equivalent to :option:`-Wformat=0`. Since
558 :option:`-Wformat` also checks for null format arguments for several
559 functions, :option:`-Wformat` also implies :option:`-Wnonnull`. Some
560 aspects of this level of format checking can be disabled by the
561 options: :option:`-Wno-format-contains-nul`,
562 :option:`-Wno-format-extra-args`, and :option:`-Wno-format-zero-length`.
563 :option:`-Wformat` is enabled by :option:`-Wall`.
564
565 .. option:: -Wformat=2
566
567 Enable :option:`-Wformat` plus additional format checks. Currently
568 equivalent to :option:`-Wformat` :option:`-Wformat-nonliteral` :option:`-Wformat-security`
569 :option:`-Wformat-y2k`.
570
571.. option:: -Wno-format
572
573 Default setting; overrides :option:`-Wformat`.
574
575.. option:: -Wno-format-contains-nul
576
577 If :option:`-Wformat` is specified, do not warn about format strings that
578 contain NUL bytes.
579
580.. option:: -Wformat-contains-nul
581
582 Default setting; overrides :option:`-Wno-format-contains-nul`.
583
584.. option:: -Wno-format-extra-args
585
586 If :option:`-Wformat` is specified, do not warn about excess arguments to a
587 ``printf`` or ``scanf`` format function. The C standard specifies
588 that such arguments are ignored.
589
590 Where the unused arguments lie between used arguments that are
591 specified with :samp:`$` operand number specifications, normally
592 warnings are still given, since the implementation could not know what
593 type to pass to ``va_arg`` to skip the unused arguments. However,
594 in the case of ``scanf`` formats, this option suppresses the
595 warning if the unused arguments are all pointers, since the Single
596 Unix Specification says that such unused arguments are allowed.
597
598.. option:: -Wformat-extra-args
599
600 Default setting; overrides :option:`-Wno-format-extra-args`.
601
602.. option:: -Wformat-overflow, -Wformat-overflow={level}
603
604 Warn about calls to formatted input/output functions such as ``sprintf``
605 and ``vsprintf`` that might overflow the destination buffer. When the
606 exact number of bytes written by a format directive cannot be determined
607 at compile-time it is estimated based on heuristics that depend on the
608 :samp:`{level}` argument and on optimization. While enabling optimization
609 will in most cases improve the accuracy of the warning, it may also
610 result in false positives.
611
612 .. option:: -Wformat-overflow, -Wformat-overflow=1
613
614 Level :samp:`{1}` of :option:`-Wformat-overflow` enabled by :option:`-Wformat`
615 employs a conservative approach that warns only about calls that most
616 likely overflow the buffer. At this level, numeric arguments to format
617 directives with unknown values are assumed to have the value of one, and
618 strings of unknown length to be empty. Numeric arguments that are known
619 to be bounded to a subrange of their type, or string arguments whose output
620 is bounded either by their directive's precision or by a finite set of
621 string literals, are assumed to take on the value within the range that
622 results in the most bytes on output. For example, the call to ``sprintf``
623 below is diagnosed because even with both :samp:`{a}` and :samp:`{b}` equal to zero,
624 the terminating NUL character (``'\0'``) appended by the function
625 to the destination buffer will be written past its end. Increasing
626 the size of the buffer by a single byte is sufficient to avoid the
627 warning, though it may not be sufficient to avoid the overflow.
628
629 .. code-block:: c++
630
631 void f (int a, int b)
632 {
633 char buf [13];
634 sprintf (buf, "a = %i, b = %i\n", a, b);
635 }
636
637 .. option:: -Wno-format-overflow
638
639 Default setting; overrides :option:`-Wformat-overflow`.
640
641 ``-Wformat-overflow=2``
642 Level :samp:`{2}` warns also about calls that might overflow the destination
643 buffer given an argument of sufficient length or magnitude. At level
644 :samp:`{2}`, unknown numeric arguments are assumed to have the minimum
645 representable value for signed types with a precision greater than 1, and
646 the maximum representable value otherwise. Unknown string arguments whose
647 length cannot be assumed to be bounded either by the directive's precision,
648 or by a finite set of string literals they may evaluate to, or the character
649 array they may point to, are assumed to be 1 character long.
650
651 At level :samp:`{2}`, the call in the example above is again diagnosed, but
652 this time because with :samp:`{a}` equal to a 32-bit ``INT_MIN`` the first
653 ``%i`` directive will write some of its digits beyond the end of
654 the destination buffer. To make the call safe regardless of the values
655 of the two variables, the size of the destination buffer must be increased
656 to at least 34 bytes. GCC includes the minimum size of the buffer in
657 an informational note following the warning.
658
659 An alternative to increasing the size of the destination buffer is to
660 constrain the range of formatted values. The maximum length of string
661 arguments can be bounded by specifying the precision in the format
662 directive. When numeric arguments of format directives can be assumed
663 to be bounded by less than the precision of their type, choosing
664 an appropriate length modifier to the format specifier will reduce
665 the required buffer size. For example, if :samp:`{a}` and :samp:`{b}` in the
666 example above can be assumed to be within the precision of
667 the ``short int`` type then using either the ``%hi`` format
668 directive or casting the argument to ``short`` reduces the maximum
669 required size of the buffer to 24 bytes.
670
671 .. code-block:: c++
672
673 void f (int a, int b)
674 {
675 char buf [23];
676 sprintf (buf, "a = %hi, b = %i\n", a, (short)b);
677 }
678
679.. option:: -Wno-format-overflow
680
681 Default setting; overrides :option:`-Wformat-overflow`.
682
683.. option:: -Wno-format-zero-length
684
685 If :option:`-Wformat` is specified, do not warn about zero-length formats.
686 The C standard specifies that zero-length formats are allowed.
687
688.. option:: -Wformat-zero-length
689
690 Default setting; overrides :option:`-Wno-format-zero-length`.
691
692.. option:: -Wformat-nonliteral
693
694 If :option:`-Wformat` is specified, also warn if the format string is not a
695 string literal and so cannot be checked, unless the format function
696 takes its format arguments as a ``va_list``.
697
698.. option:: -Wno-format-nonliteral
699
700 Default setting; overrides :option:`-Wformat-nonliteral`.
701
702.. option:: -Wformat-security
703
704 If :option:`-Wformat` is specified, also warn about uses of format
705 functions that represent possible security problems. At present, this
706 warns about calls to ``printf`` and ``scanf`` functions where the
707 format string is not a string literal and there are no format arguments,
708 as in ``printf (foo);``. This may be a security hole if the format
709 string came from untrusted input and contains :samp:`%n`. (This is
710 currently a subset of what :option:`-Wformat-nonliteral` warns about, but
711 in future warnings may be added to :option:`-Wformat-security` that are not
712 included in :option:`-Wformat-nonliteral`.)
713
714.. option:: -Wno-format-security
715
716 Default setting; overrides :option:`-Wformat-security`.
717
718.. option:: -Wformat-signedness
719
720 If :option:`-Wformat` is specified, also warn if the format string
721 requires an unsigned argument and the argument is signed and vice versa.
722
723.. option:: -Wno-format-signedness
724
725 Default setting; overrides :option:`-Wformat-signedness`.
726
727.. option:: -Wformat-truncation, -Wformat-truncation={level}
728
729 Warn about calls to formatted input/output functions such as ``snprintf``
730 and ``vsnprintf`` that might result in output truncation. When the exact
731 number of bytes written by a format directive cannot be determined at
732 compile-time it is estimated based on heuristics that depend on
733 the :samp:`{level}` argument and on optimization. While enabling optimization
734 will in most cases improve the accuracy of the warning, it may also result
735 in false positives. Except as noted otherwise, the option uses the same
736 logic :option:`-Wformat-overflow`.
737
738 .. option:: -Wformat-truncation, -Wformat-truncation=1
739
740 Level :samp:`{1}` of :option:`-Wformat-truncation` enabled by :option:`-Wformat`
741 employs a conservative approach that warns only about calls to bounded
742 functions whose return value is unused and that will most likely result
743 in output truncation.
744
745 .. option:: -Wformat-truncation=2
746
747 Level :samp:`{2}` warns also about calls to bounded functions whose return
748 value is used and that might result in truncation given an argument of
749 sufficient length or magnitude.
750
751.. option:: -Wno-format-truncation
752
753 Default setting; overrides :option:`-Wformat-truncation`.
754
755.. option:: -Wformat-y2k
756
757 If :option:`-Wformat` is specified, also warn about ``strftime``
758 formats that may yield only a two-digit year.
759
760.. option:: -Wno-format-y2k
761
762 Default setting; overrides :option:`-Wformat-y2k`.
763
764.. option:: -Wnonnull
765
766 Warn about passing a null pointer for arguments marked as
767 requiring a non-null value by the :fn-attr:`nonnull` function attribute.
768
769 :option:`-Wnonnull` is included in :option:`-Wall` and :option:`-Wformat`. It
770 can be disabled with the :option:`-Wno-nonnull` option.
771
772.. option:: -Wno-nonnull
773
774 Default setting; overrides :option:`-Wnonnull`.
775
776.. option:: -Wnonnull-compare
777
778 Warn when comparing an argument marked with the :fn-attr:`nonnull`
779 function attribute against null inside the function.
780
781 :option:`-Wnonnull-compare` is included in :option:`-Wall`. It
782 can be disabled with the :option:`-Wno-nonnull-compare` option.
783
784.. option:: -Wno-nonnull-compare
785
786 Default setting; overrides :option:`-Wnonnull-compare`.
787
788.. option:: -Wnull-dereference
789
790 Warn if the compiler detects paths that trigger erroneous or
791 undefined behavior due to dereferencing a null pointer. This option
792 is only active when :option:`-fdelete-null-pointer-checks` is active,
793 which is enabled by optimizations in most targets. The precision of
794 the warnings depends on the optimization options used.
795
796.. option:: -Wno-null-dereference
797
798 Default setting; overrides :option:`-Wnull-dereference`.
799
800.. option:: -Winfinite-recursion
801
802 Warn about infinitely recursive calls. The warning is effective at all
803 optimization levels but requires optimization in order to detect infinite
804 recursion in calls between two or more functions.
805 :option:`-Winfinite-recursion` is included in :option:`-Wall`.
806
807.. option:: -Wno-infinite-recursion
808
809 Default setting; overrides :option:`-Winfinite-recursion`.
810
811.. option:: -Winit-self
812
813 .. note::
814
815 C, C++, Objective-C and Objective-C++ only
816
817 Warn about uninitialized variables that are initialized with themselves.
818 Note this option can only be used with the :option:`-Wuninitialized` option.
819
820 For example, GCC warns about ``i`` being uninitialized in the
821 following snippet only when :option:`-Winit-self` has been specified:
822
823 .. code-block:: c++
824
825 int f()
826 {
827 int i = i;
828 return i;
829 }
830
831 This warning is enabled by :option:`-Wall` in C++.
832
833.. option:: -Wno-init-self
834
835 Default setting; overrides :option:`-Winit-self`.
836
837.. option:: -Wno-implicit-int
838
839 .. note::
840
841 C and Objective-C only
842
843 This option controls warnings when a declaration does not specify a type.
844 This warning is enabled by default in C99 and later dialects of C,
845 and also by :option:`-Wall`.
846
847.. option:: -Wimplicit-int
848
849 Default setting; overrides :option:`-Wno-implicit-int`.
850
851.. option:: -Wno-implicit-function-declaration
852
853 .. note::
854
855 C and Objective-C only
856
857 This option controls warnings when a function is used before being declared.
858 This warning is enabled by default in C99 and later dialects of C,
859 and also by :option:`-Wall`.
860 The warning is made into an error by :option:`-pedantic-errors`.
861
862.. option:: -Wimplicit-function-declaration
863
864 Default setting; overrides :option:`-Wno-implicit-function-declaration`.
865
866.. option:: -Wimplicit
867
868 .. note::
869
870 C and Objective-C only
871
872 Same as :option:`-Wimplicit-int` and :option:`-Wimplicit-function-declaration`.
873 This warning is enabled by :option:`-Wall`.
874
875.. option:: -Wno-implicit
876
877 Default setting; overrides :option:`-Wimplicit`.
878
879.. option:: -Wimplicit-fallthrough
880
881 :option:`-Wimplicit-fallthrough` is the same as :option:`-Wimplicit-fallthrough=3`
882 and :option:`-Wno-implicit-fallthrough` is the same as
883 :option:`-Wimplicit-fallthrough=0`.
884
885.. option:: -Wno-implicit-fallthrough
886
887 Default setting; overrides :option:`-Wimplicit-fallthrough`.
888
889.. option:: -Wimplicit-fallthrough={n}
890
891 Warn when a switch case falls through. For example:
892
893 .. code-block:: c++
894
895 switch (cond)
896 {
897 case 1:
898 a = 1;
899 break;
900 case 2:
901 a = 2;
902 case 3:
903 a = 3;
904 break;
905 }
906
907 This warning does not warn when the last statement of a case cannot
908 fall through, e.g. when there is a return statement or a call to function
909 declared with the noreturn attribute. :option:`-Wimplicit-fallthrough=`
910 also takes into account control flow statements, such as ifs, and only
911 warns when appropriate. E.g.
912
913 .. code-block:: c++
914
915 switch (cond)
916 {
917 case 1:
918 if (i > 3) {
919 bar (5);
920 break;
921 } else if (i < 1) {
922 bar (0);
923 } else
924 return;
925 default:
926 ...
927 }
928
929 Since there are occasions where a switch case fall through is desirable,
930 GCC provides an attribute, ``__attribute__ ((fallthrough))``, that is
931 to be used along with a null statement to suppress this warning that
932 would normally occur:
933
934 .. code-block:: c++
935
936 switch (cond)
937 {
938 case 1:
939 bar (0);
940 __attribute__ ((fallthrough));
941 default:
942 ...
943 }
944
945 C++17 provides a standard way to suppress the :option:`-Wimplicit-fallthrough`
946 warning using ``[[fallthrough]];`` instead of the GNU attribute. In C++11
947 or C++14 users can use ``[[gnu::fallthrough]];``, which is a GNU extension.
948 Instead of these attributes, it is also possible to add a fallthrough comment
949 to silence the warning. The whole body of the C or C++ style comment should
950 match the given regular expressions listed below. The option argument :samp:`{n}`
951 specifies what kind of comments are accepted:
952
953 * :option:`-Wimplicit-fallthrough=0` disables the warning altogether.
954
955 * :option:`-Wimplicit-fallthrough=1` matches ``.*`` regular
956 expression, any comment is used as fallthrough comment.
957
958 * :option:`-Wimplicit-fallthrough=2` case insensitively matches
959 ``.*falls?[ \t-]*thr(ough|u).*`` regular expression.
960
961 * :option:`-Wimplicit-fallthrough=3` case sensitively matches one of the
962 following regular expressions:
963
964 * ``-fallthrough``
965
966 * ``@fallthrough@``
967
968 * ``lint -fallthrough[ \t]*``
969
970 * ``[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
971 FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?``
972
973 * ``[ \t.!]*(Else,? |Intentional(ly)? )?
974 Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?``
975
976 * ``[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
977 fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?``
978
979 * :option:`-Wimplicit-fallthrough=4` case sensitively matches one of the
980 following regular expressions:
981
982 * ``-fallthrough``
983
984 * ``@fallthrough@``
985
986 * ``lint -fallthrough[ \t]*``
987
988 * ``[ \t]*FALLTHR(OUGH|U)[ \t]*``
989
990 * :option:`-Wimplicit-fallthrough=5` doesn't recognize any comments as
991 fallthrough comments, only attributes disable the warning.
992
993 The comment needs to be followed after optional whitespace and other comments
994 by ``case`` or ``default`` keywords or by a user label that precedes some
995 ``case`` or ``default`` label.
996
997 .. code-block:: c++
998
999 switch (cond)
1000 {
1001 case 1:
1002 bar (0);
1003 /* FALLTHRU */
1004 default:
1005 ...
1006 }
1007
1008 The :option:`-Wimplicit-fallthrough=3` warning is enabled by :option:`-Wextra`.
1009
1010.. option:: -Wno-if-not-aligned
1011
1012 .. note::
1013
1014 C, C++, Objective-C and Objective-C++ only
1015
1016 Control if warnings triggered by the ``warn_if_not_aligned`` attribute
1017 should be issued. These warnings are enabled by default.
1018
1019.. option:: -Wif-not-aligned
1020
1021 Default setting; overrides :option:`-Wno-if-not-aligned`.
1022
1023.. option:: -Wignored-qualifiers
1024
1025 .. note::
1026
1027 C and C++ only
1028
1029 Warn if the return type of a function has a type qualifier
1030 such as ``const``. For ISO C such a type qualifier has no effect,
1031 since the value returned by a function is not an lvalue.
1032 For C++, the warning is only emitted for scalar types or ``void``.
1033 ISO C prohibits qualified ``void`` return types on function
1034 definitions, so such return types always receive a warning
1035 even without this option.
1036
1037 This warning is also enabled by :option:`-Wextra`.
1038
1039.. option:: -Wno-ignored-qualifiers
1040
1041 Default setting; overrides :option:`-Wignored-qualifiers`.
1042
1043.. option:: -Wno-ignored-attributes
1044
1045 .. note::
1046
1047 C and C++ only
1048
1049 This option controls warnings when an attribute is ignored.
1050 This is different from the
1051 :option:`-Wattributes` option in that it warns whenever the compiler decides
1052 to drop an attribute, not that the attribute is either unknown, used in a
1053 wrong place, etc. This warning is enabled by default.
1054
1055.. option:: -Wignored-attributes
1056
1057 Default setting; overrides :option:`-Wno-ignored-attributes`.
1058
1059.. option:: -Wmain
1060
1061 Warn if the type of ``main`` is suspicious. ``main`` should be
1062 a function with external linkage, returning int, taking either zero
1063 arguments, two, or three arguments of appropriate types. This warning
1064 is enabled by default in C++ and is enabled by either :option:`-Wall`
1065 or :option:`-Wpedantic`.
1066
1067.. option:: -Wno-main
1068
1069 Default setting; overrides :option:`-Wmain`.
1070
1071.. option:: -Wmisleading-indentation
1072
1073 .. note::
1074
1075 C and C++ only
1076
1077 Warn when the indentation of the code does not reflect the block structure.
1078 Specifically, a warning is issued for ``if``, ``else``, ``while``, and
1079 ``for`` clauses with a guarded statement that does not use braces,
1080 followed by an unguarded statement with the same indentation.
1081
1082 In the following example, the call to 'bar' is misleadingly indented as
1083 if it were guarded by the 'if' conditional.
1084
1085 .. code-block:: c++
1086
1087 if (some_condition ())
1088 foo ();
1089 bar (); /* Gotcha: this is not guarded by the "if". */
1090
1091 In the case of mixed tabs and spaces, the warning uses the
1092 :option:`-ftabstop=` option to determine if the statements line up
1093 (defaulting to 8).
1094
1095 The warning is not issued for code involving multiline preprocessor logic
1096 such as the following example.
1097
1098 .. code-block:: c++
1099
1100 if (flagA)
1101 foo (0);
1102 #if SOME_CONDITION_THAT_DOES_NOT_HOLD
1103 if (flagB)
1104 #endif
1105 foo (1);
1106
1107 The warning is not issued after a ``#line`` directive, since this
1108 typically indicates autogenerated code, and no assumptions can be made
1109 about the layout of the file that the directive references.
1110
1111 This warning is enabled by :option:`-Wall` in C and C++.
1112
1113.. option:: -Wno-misleading-indentation
1114
1115 Default setting; overrides :option:`-Wmisleading-indentation`.
1116
1117.. option:: -Wmissing-attributes
1118
1119 Warn when a declaration of a function is missing one or more attributes
1120 that a related function is declared with and whose absence may adversely
1121 affect the correctness or efficiency of generated code. For example,
1122 the warning is issued for declarations of aliases that use attributes
1123 to specify less restrictive requirements than those of their targets.
1124 This typically represents a potential optimization opportunity.
1125 By contrast, the :option:`-Wattribute-alias=2` option controls warnings
1126 issued when the alias is more restrictive than the target, which could
1127 lead to incorrect code generation.
1128 Attributes considered include ``alloc_align``, ``alloc_size``,
1129 :fn-attr:`cold`, :fn-attr:`const`, :fn-attr:`hot`, :fn-attr:`leaf`, :fn-attr:`malloc`,
1130 :fn-attr:`nonnull`, :fn-attr:`noreturn`, :fn-attr:`nothrow`, :fn-attr:`pure`,
1131 :fn-attr:`returns_nonnull`, and :fn-attr:`returns_twice`.
1132
1133 In C++, the warning is issued when an explicit specialization of a primary
1134 template declared with attribute ``alloc_align``, ``alloc_size``,
1135 ``assume_aligned``, ``format``, ``format_arg``, ``malloc``,
1136 or :fn-attr:`nonnull` is declared without it. Attributes :fn-attr:`deprecated`,
1137 ``error``, and ``warning`` suppress the warning.
1138 (see :ref:`function-attributes`).
1139
1140 You can use the ``copy`` attribute to apply the same
1141 set of attributes to a declaration as that on another declaration without
1142 explicitly enumerating the attributes. This attribute can be applied
1143 to declarations of functions (see :ref:`common-function-attributes`),
1144 variables (see :ref:`common-variable-attributes`), or types
1145 (see :ref:`common-type-attributes`).
1146
1147 :option:`-Wmissing-attributes` is enabled by :option:`-Wall`.
1148
1149 For example, since the declaration of the primary function template
1150 below makes use of both attribute ``malloc`` and ``alloc_size``
1151 the declaration of the explicit specialization of the template is
1152 diagnosed because it is missing one of the attributes.
1153
1154 .. code-block:: c++
1155
1156 template <class T>
1157 T* __attribute__ ((malloc, alloc_size (1)))
1158 allocate (size_t);
1159
1160 template <>
1161 void* __attribute__ ((malloc)) // missing alloc_size
1162 allocate<void> (size_t);
1163
1164.. option:: -Wno-missing-attributes
1165
1166 Default setting; overrides :option:`-Wmissing-attributes`.
1167
1168.. option:: -Wmissing-braces
1169
1170 Warn if an aggregate or union initializer is not fully bracketed. In
1171 the following example, the initializer for ``a`` is not fully
1172 bracketed, but that for ``b`` is fully bracketed.
1173
1174 .. code-block:: c++
1175
1176 int a[2][2] = { 0, 1, 2, 3 };
1177 int b[2][2] = { { 0, 1 }, { 2, 3 } };
1178
1179 This warning is enabled by :option:`-Wall`.
1180
1181.. option:: -Wno-missing-braces
1182
1183 Default setting; overrides :option:`-Wmissing-braces`.
1184
1185.. option:: -Wmissing-include-dirs
1186
1187 .. note::
1188
1189 C, C++, Objective-C, Objective-C++ and Fortran only
1190
1191 Warn if a user-supplied include directory does not exist. This opions is disabled
1192 by default for C, C++, Objective-C and Objective-C++. For Fortran, it is partially
1193 enabled by default by warning for -I and -J, only.
1194
1195.. option:: -Wno-missing-include-dirs
1196
1197 Default setting; overrides :option:`-Wmissing-include-dirs`.
1198
1199.. option:: -Wno-missing-profile
1200
1201 This option controls warnings if feedback profiles are missing when using the
1202 :option:`-fprofile-use` option.
1203 This option diagnoses those cases where a new function or a new file is added
1204 between compiling with :option:`-fprofile-generate` and with
1205 :option:`-fprofile-use`, without regenerating the profiles.
1206 In these cases, the profile feedback data files do not contain any
1207 profile feedback information for
1208 the newly added function or file respectively. Also, in the case when profile
1209 count data (.gcda) files are removed, GCC cannot use any profile feedback
1210 information. In all these cases, warnings are issued to inform you that a
1211 profile generation step is due.
1212 Ignoring the warning can result in poorly optimized code.
1213 :option:`-Wno-missing-profile` can be used to
1214 disable the warning, but this is not recommended and should be done only
1215 when non-existent profile data is justified.
1216
1217.. option:: -Wmissing-profile
1218
1219 Default setting; overrides :option:`-Wno-missing-profile`.
1220
1221.. option:: -Wmismatched-dealloc
1222
1223 Warn for calls to deallocation functions with pointer arguments returned
1224 from from allocations functions for which the former isn't a suitable
1225 deallocator. A pair of functions can be associated as matching allocators
1226 and deallocators by use of attribute ``malloc``. Unless disabled by
1227 the :option:`-fno-builtin` option the standard functions ``calloc``,
1228 ``malloc``, ``realloc``, and ``free``, as well as the corresponding
1229 forms of C++ ``operator new`` and ``operator delete`` are implicitly
1230 associated as matching allocators and deallocators. In the following
1231 example ``mydealloc`` is the deallocator for pointers returned from
1232 ``myalloc``.
1233
1234 .. code-block:: c++
1235
1236 void mydealloc (void*);
1237
1238 __attribute__ ((malloc (mydealloc, 1))) void*
1239 myalloc (size_t);
1240
1241 void f (void)
1242 {
1243 void *p = myalloc (32);
1244 // ...use p...
1245 free (p); // warning: not a matching deallocator for myalloc
1246 mydealloc (p); // ok
1247 }
1248
1249 In C++, the related option :option:`-Wmismatched-new-delete` diagnoses
1250 mismatches involving either ``operator new`` or ``operator delete``.
1251
1252 Option :option:`-Wmismatched-dealloc` is included in :option:`-Wall`.
1253
1254.. option:: -Wno-mismatched-dealloc
1255
1256 Default setting; overrides :option:`-Wmismatched-dealloc`.
1257
1258.. option:: -Wmultistatement-macros
1259
1260 Warn about unsafe multiple statement macros that appear to be guarded
1261 by a clause such as ``if``, ``else``, ``for``, ``switch``, or
1262 ``while``, in which only the first statement is actually guarded after
1263 the macro is expanded.
1264
1265 For example:
1266
1267 .. code-block:: c++
1268
1269 #define DOIT x++; y++
1270 if (c)
1271 DOIT;
1272
1273 will increment ``y`` unconditionally, not just when ``c`` holds.
1274 The can usually be fixed by wrapping the macro in a do-while loop:
1275
1276 .. code-block:: c++
1277
1278 #define DOIT do { x++; y++; } while (0)
1279 if (c)
1280 DOIT;
1281
1282 This warning is enabled by :option:`-Wall` in C and C++.
1283
1284.. option:: -Wno-multistatement-macros
1285
1286 Default setting; overrides :option:`-Wmultistatement-macros`.
1287
1288.. option:: -Wparentheses
1289
1290 Warn if parentheses are omitted in certain contexts, such
1291 as when there is an assignment in a context where a truth value
1292 is expected, or when operators are nested whose precedence people
1293 often get confused about.
1294
1295 Also warn if a comparison like ``x<=y<=z`` appears; this is
1296 equivalent to ``(x<=y ? 1 : 0) <= z``, which is a different
1297 interpretation from that of ordinary mathematical notation.
1298
1299 Also warn for dangerous uses of the GNU extension to
1300 ``?:`` with omitted middle operand. When the condition
1301 in the ``?`` : operator is a boolean expression, the omitted value is
1302 always 1. Often programmers expect it to be a value computed
1303 inside the conditional expression instead.
1304
1305 For C++ this also warns for some cases of unnecessary parentheses in
1306 declarations, which can indicate an attempt at a function call instead
1307 of a declaration:
1308
1309 .. code-block:: c++
1310
1311 {
1312 // Declares a local variable called mymutex.
1313 std::unique_lock<std::mutex> (mymutex);
1314 // User meant std::unique_lock<std::mutex> lock (mymutex);
1315 }
1316
1317 This warning is enabled by :option:`-Wall`.
1318
1319.. option:: -Wno-parentheses
1320
1321 Default setting; overrides :option:`-Wparentheses`.
1322
1323.. option:: -Wno-self-move
1324
1325 .. note::
1326
1327 C++ and Objective-C++ only
1328
1329 This warning warns when a value is moved to itself with ``std::move``.
1330 Such a ``std::move`` typically has no effect.
1331
1332 .. code-block:: c++
1333
1334 struct T {
1335 ...
1336 };
1337 void fn()
1338 {
1339 T t;
1340 ...
1341 t = std::move (t);
1342 }
1343
1344 This warning is enabled by :option:`-Wall`.
1345
1346.. option:: -Wself-move
1347
1348 Default setting; overrides :option:`-Wno-self-move`.
1349
1350.. option:: -Wsequence-point
1351
1352 Warn about code that may have undefined semantics because of violations
1353 of sequence point rules in the C and C++ standards.
1354
1355 The C and C++ standards define the order in which expressions in a C/C++
1356 program are evaluated in terms of :dfn:`sequence points`, which represent
1357 a partial ordering between the execution of parts of the program: those
1358 executed before the sequence point, and those executed after it. These
1359 occur after the evaluation of a full expression (one which is not part
1360 of a larger expression), after the evaluation of the first operand of a
1361 ``&&``, ``||``, ``? :`` or ``,`` (comma) operator, before a
1362 function is called (but after the evaluation of its arguments and the
1363 expression denoting the called function), and in certain other places.
1364 Other than as expressed by the sequence point rules, the order of
1365 evaluation of subexpressions of an expression is not specified. All
1366 these rules describe only a partial order rather than a total order,
1367 since, for example, if two functions are called within one expression
1368 with no sequence point between them, the order in which the functions
1369 are called is not specified. However, the standards committee have
1370 ruled that function calls do not overlap.
1371
1372 It is not specified when between sequence points modifications to the
1373 values of objects take effect. Programs whose behavior depends on this
1374 have undefined behavior; the C and C++ standards specify that 'Between
1375 the previous and next sequence point an object shall have its stored
1376 value modified at most once by the evaluation of an expression.
1377 Furthermore, the prior value shall be read only to determine the value
1378 to be stored.'. If a program breaks these rules, the results on any
1379 particular implementation are entirely unpredictable.
1380
1381 Examples of code with undefined behavior are ``a = a++;``, ``a[n]
1382 = b[n++]`` and ``a[i++] = i;``. Some more complicated cases are not
1383 diagnosed by this option, and it may give an occasional false positive
1384 result, but in general it has been found fairly effective at detecting
1385 this sort of problem in programs.
1386
1387 The C++17 standard will define the order of evaluation of operands in
1388 more cases: in particular it requires that the right-hand side of an
1389 assignment be evaluated before the left-hand side, so the above
1390 examples are no longer undefined. But this option will still warn
1391 about them, to help people avoid writing code that is undefined in C
1392 and earlier revisions of C++.
1393
1394 The standard is worded confusingly, therefore there is some debate
1395 over the precise meaning of the sequence point rules in subtle cases.
1396 Links to discussions of the problem, including proposed formal
1397 definitions, may be found on the GCC readings page, at
1398 https://gcc.gnu.org/readings.html.
1399
1400 This warning is enabled by :option:`-Wall` for C and C++.
1401
1402.. option:: -Wno-sequence-point
1403
1404 Default setting; overrides :option:`-Wsequence-point`.
1405
1406.. option:: -Wno-return-local-addr
1407
1408 Do not warn about returning a pointer (or in C++, a reference) to a
1409 variable that goes out of scope after the function returns.
1410
1411.. option:: -Wreturn-local-addr
1412
1413 Default setting; overrides :option:`-Wno-return-local-addr`.
1414
1415.. option:: -Wreturn-type
1416
1417 Warn whenever a function is defined with a return type that defaults
1418 to ``int``. Also warn about any ``return`` statement with no
1419 return value in a function whose return type is not ``void``
1420 (falling off the end of the function body is considered returning
1421 without a value).
1422
1423 For C only, warn about a ``return`` statement with an expression in a
1424 function whose return type is ``void``, unless the expression type is
1425 also ``void``. As a GNU extension, the latter case is accepted
1426 without a warning unless :option:`-Wpedantic` is used. Attempting
1427 to use the return value of a non- ``void`` function other than ``main``
1428 that flows off the end by reaching the closing curly brace that terminates
1429 the function is undefined.
1430
1431 Unlike in C, in C++, flowing off the end of a non- ``void`` function other
1432 than ``main`` results in undefined behavior even when the value of
1433 the function is not used.
1434
1435 This warning is enabled by default in C++ and by :option:`-Wall` otherwise.
1436
1437.. option:: -Wno-return-type
1438
1439 Default setting; overrides :option:`-Wreturn-type`.
1440
1441.. option:: -Wno-shift-count-negative
1442
1443 Controls warnings if a shift count is negative.
1444 This warning is enabled by default.
1445
1446.. option:: -Wshift-count-negative
1447
1448 Default setting; overrides :option:`-Wno-shift-count-negative`.
1449
1450.. option:: -Wno-shift-count-overflow
1451
1452 Controls warnings if a shift count is greater than or equal to the bit width
1453 of the type. This warning is enabled by default.
1454
1455.. option:: -Wshift-count-overflow
1456
1457 Default setting; overrides :option:`-Wno-shift-count-overflow`.
1458
1459.. option:: -Wshift-negative-value
1460
1461 Warn if left shifting a negative value. This warning is enabled by
1462 :option:`-Wextra` in C99 (and newer) and C++11 to C++17 modes.
1463
1464.. option:: -Wno-shift-negative-value
1465
1466 Default setting; overrides :option:`-Wshift-negative-value`.
1467
1468.. option:: -Wno-shift-overflow, -Wshift-overflow={n}
1469
1470 These options control warnings about left shift overflows.
1471
1472 ``-Wshift-overflow=1``
1473 This is the warning level of :option:`-Wshift-overflow` and is enabled
1474 by default in C99 and C++11 modes (and newer). This warning level does
1475 not warn about left-shifting 1 into the sign bit. (However, in C, such
1476 an overflow is still rejected in contexts where an integer constant expression
1477 is required.) No warning is emitted in C++20 mode (and newer), as signed left
1478 shifts always wrap.
1479
1480 ``-Wshift-overflow=2``
1481 This warning level also warns about left-shifting 1 into the sign bit,
1482 unless C++14 mode (or newer) is active.
1483
1484.. option:: -Wshift-overflow
1485
1486 Default setting; overrides :option:`-Wno-shift-overflow`.
1487
1488.. option:: -Wswitch
1489
1490 Warn whenever a ``switch`` statement has an index of enumerated type
1491 and lacks a ``case`` for one or more of the named codes of that
1492 enumeration. (The presence of a ``default`` label prevents this
1493 warning.) ``case`` labels outside the enumeration range also
1494 provoke warnings when this option is used (even if there is a
1495 ``default`` label).
1496 This warning is enabled by :option:`-Wall`.
1497
1498.. option:: -Wno-switch
1499
1500 Default setting; overrides :option:`-Wswitch`.
1501
1502.. option:: -Wswitch-default
1503
1504 Warn whenever a ``switch`` statement does not have a ``default``
1505 case.
1506
1507.. option:: -Wno-switch-default
1508
1509 Default setting; overrides :option:`-Wswitch-default`.
1510
1511.. option:: -Wswitch-enum
1512
1513 Warn whenever a ``switch`` statement has an index of enumerated type
1514 and lacks a ``case`` for one or more of the named codes of that
1515 enumeration. ``case`` labels outside the enumeration range also
1516 provoke warnings when this option is used. The only difference
1517 between :option:`-Wswitch` and this option is that this option gives a
1518 warning about an omitted enumeration code even if there is a
1519 ``default`` label.
1520
1521.. option:: -Wno-switch-enum
1522
1523 Default setting; overrides :option:`-Wswitch-enum`.
1524
1525.. option:: -Wno-switch-bool
1526
1527 Do not warn when a ``switch`` statement has an index of boolean type
1528 and the case values are outside the range of a boolean type.
1529 It is possible to suppress this warning by casting the controlling
1530 expression to a type other than ``bool``. For example:
1531
1532 .. code-block:: c++
1533
1534 switch ((int) (a == 4))
1535 {
1536 ...
1537 }
1538
1539 This warning is enabled by default for C and C++ programs.
1540
1541.. option:: -Wswitch-bool
1542
1543 Default setting; overrides :option:`-Wno-switch-bool`.
1544
1545.. option:: -Wno-switch-outside-range
1546
1547 This option controls warnings when a ``switch`` case has a value
1548 that is outside of its
1549 respective type range. This warning is enabled by default for
1550 C and C++ programs.
1551
1552.. option:: -Wswitch-outside-range
1553
1554 Default setting; overrides :option:`-Wno-switch-outside-range`.
1555
1556.. option:: -Wno-switch-unreachable
1557
1558 Do not warn when a ``switch`` statement contains statements between the
1559 controlling expression and the first case label, which will never be
1560 executed. For example:
1561
1562 .. code-block:: c++
1563
1564 switch (cond)
1565 {
1566 i = 15;
1567 ...
1568 case 5:
1569 ...
1570 }
1571
1572 :option:`-Wswitch-unreachable` does not warn if the statement between the
1573 controlling expression and the first case label is just a declaration:
1574
1575 .. code-block:: c++
1576
1577 switch (cond)
1578 {
1579 int i;
1580 ...
1581 case 5:
1582 i = 5;
1583 ...
1584 }
1585
1586 This warning is enabled by default for C and C++ programs.
1587
1588.. option:: -Wswitch-unreachable
1589
1590 Default setting; overrides :option:`-Wno-switch-unreachable`.
1591
1592.. option:: -Wsync-nand
1593
1594 .. note::
1595
1596 C and C++ only
1597
1598 Warn when ``__sync_fetch_and_nand`` and ``__sync_nand_and_fetch``
1599 built-in functions are used. These functions changed semantics in GCC 4.4.
1600
1601.. option:: -Wno-sync-nand
1602
1603 Default setting; overrides :option:`-Wsync-nand`.
1604
1605.. option:: -Wtrivial-auto-var-init
1606
1607 Warn when ``-ftrivial-auto-var-init`` cannot initialize the automatic
1608 variable. A common situation is an automatic variable that is declared
1609 between the controlling expression and the first case label of a ``switch``
1610 statement.
1611
1612.. option:: -Wno-trivial-auto-var-init
1613
1614 Default setting; overrides :option:`-Wtrivial-auto-var-init`.
1615
1616.. option:: -Wunused-but-set-parameter
1617
1618 Warn whenever a function parameter is assigned to, but otherwise unused
1619 (aside from its declaration).
1620
1621 To suppress this warning use the :var-attr:`unused` attribute
1622 (see :ref:`variable-attributes`).
1623
1624 This warning is also enabled by :option:`-Wunused` together with
1625 :option:`-Wextra`.
1626
1627.. option:: -Wno-unused-but-set-parameter
1628
1629 Default setting; overrides :option:`-Wunused-but-set-parameter`.
1630
1631.. option:: -Wunused-but-set-variable
1632
1633 Warn whenever a local variable is assigned to, but otherwise unused
1634 (aside from its declaration).
1635 This warning is enabled by :option:`-Wall`.
1636
1637 To suppress this warning use the :var-attr:`unused` attribute
1638 (see :ref:`variable-attributes`).
1639
1640 This warning is also enabled by :option:`-Wunused`, which is enabled
1641 by :option:`-Wall`.
1642
1643.. option:: -Wno-unused-but-set-variable
1644
1645 Default setting; overrides :option:`-Wunused-but-set-variable`.
1646
1647.. option:: -Wunused-function
1648
1649 Warn whenever a static function is declared but not defined or a
1650 non-inline static function is unused.
1651 This warning is enabled by :option:`-Wall`.
1652
1653.. option:: -Wno-unused-function
1654
1655 Default setting; overrides :option:`-Wunused-function`.
1656
1657.. option:: -Wunused-label
1658
1659 Warn whenever a label is declared but not used.
1660 This warning is enabled by :option:`-Wall`.
1661
1662 To suppress this warning use the :var-attr:`unused` attribute
1663 (see :ref:`variable-attributes`).
1664
1665.. option:: -Wno-unused-label
1666
1667 Default setting; overrides :option:`-Wunused-label`.
1668
1669.. option:: -Wunused-local-typedefs
1670
1671 .. note::
1672
1673 C, Objective-C, C++ and Objective-C++ only
1674
1675 Warn when a typedef locally defined in a function is not used.
1676 This warning is enabled by :option:`-Wall`.
1677
1678.. option:: -Wno-unused-local-typedefs
1679
1680 Default setting; overrides :option:`-Wunused-local-typedefs`.
1681
1682.. option:: -Wunused-parameter
1683
1684 Warn whenever a function parameter is unused aside from its declaration.
1685
1686 To suppress this warning use the :var-attr:`unused` attribute
1687 (see :ref:`variable-attributes`).
1688
1689.. option:: -Wno-unused-parameter
1690
1691 Default setting; overrides :option:`-Wunused-parameter`.
1692
1693.. option:: -Wno-unused-result
1694
1695 Do not warn if a caller of a function marked with attribute
1696 :fn-attr:`warn_unused_result` (see :ref:`function-attributes`) does not use
1697 its return value. The default is :option:`-Wunused-result`.
1698
1699.. option:: -Wunused-result
1700
1701 Default setting; overrides :option:`-Wno-unused-result`.
1702
1703.. option:: -Wunused-variable
1704
1705 Warn whenever a local or static variable is unused aside from its
1706 declaration. This option implies :option:`-Wunused-const-variable=1` for C,
1707 but not for C++. This warning is enabled by :option:`-Wall`.
1708
1709 To suppress this warning use the :var-attr:`unused` attribute
1710 (see :ref:`variable-attributes`).
1711
1712.. option:: -Wno-unused-variable
1713
1714 Default setting; overrides :option:`-Wunused-variable`.
1715
1716.. option:: -Wunused-const-variable, -Wunused-const-variable={n}
1717
1718 Warn whenever a constant static variable is unused aside from its declaration.
1719 :option:`-Wunused-const-variable=1` is enabled by :option:`-Wunused-variable`
1720 for C, but not for C++. In C this declares variable storage, but in C++ this
1721 is not an error since const variables take the place of ``#define`` s.
1722
1723 To suppress this warning use the :var-attr:`unused` attribute
1724 (see :ref:`variable-attributes`).
1725
1726 ``-Wunused-const-variable=1``
1727 This is the warning level that is enabled by :option:`-Wunused-variable` for
1728 C. It warns only about unused static const variables defined in the main
1729 compilation unit, but not about static const variables declared in any
1730 header included.
1731
1732 ``-Wunused-const-variable=2``
1733 This warning level also warns for unused constant static variables in
1734 headers (excluding system headers). This is the warning level of
1735 :option:`-Wunused-const-variable` and must be explicitly requested since
1736 in C++ this isn't an error and in C it might be harder to clean up all
1737 headers included.
1738
1739.. option:: -Wno-unused-const-variable
1740
1741 Default setting; overrides :option:`-Wunused-const-variable`.
1742
1743.. option:: -Wunused-value
1744
1745 Warn whenever a statement computes a result that is explicitly not
1746 used. To suppress this warning cast the unused expression to
1747 ``void``. This includes an expression-statement or the left-hand
1748 side of a comma expression that contains no side effects. For example,
1749 an expression such as ``x[i,j]`` causes a warning, while
1750 ``x[(void)i,j]`` does not.
1751
1752 This warning is enabled by :option:`-Wall`.
1753
1754.. option:: -Wno-unused-value
1755
1756 Default setting; overrides :option:`-Wunused-value`.
1757
1758.. option:: -Wunused
1759
1760 All the above :option:`-Wunused` options combined.
1761
1762 In order to get a warning about an unused function parameter, you must
1763 either specify :option:`-Wextra -Wunused` (note that :option:`-Wall` implies
1764 :option:`-Wunused`), or separately specify :option:`-Wunused-parameter`.
1765
1766.. option:: -Wno-unused
1767
1768 Default setting; overrides :option:`-Wunused`.
1769
1770.. option:: -Wuninitialized
1771
1772 Warn if an object with automatic or allocated storage duration is used
1773 without having been initialized. In C++, also warn if a non-static
1774 reference or non-static ``const`` member appears in a class without
1775 constructors.
1776
1777 In addition, passing a pointer (or in C++, a reference) to an uninitialized
1778 object to a ``const`` -qualified argument of a built-in function known to
1779 read the object is also diagnosed by this warning.
1780 (:option:`-Wmaybe-uninitialized` is issued for ordinary functions.)
1781
1782 If you want to warn about code that uses the uninitialized value of the
1783 variable in its own initializer, use the :option:`-Winit-self` option.
1784
1785 These warnings occur for individual uninitialized elements of
1786 structure, union or array variables as well as for variables that are
1787 uninitialized as a whole. They do not occur for variables or elements
1788 declared ``volatile``. Because these warnings depend on
1789 optimization, the exact variables or elements for which there are
1790 warnings depend on the precise optimization options and version of GCC
1791 used.
1792
1793 Note that there may be no warning about a variable that is used only
1794 to compute a value that itself is never used, because such
1795 computations may be deleted by data flow analysis before the warnings
1796 are printed.
1797
1798 In C++, this warning also warns about using uninitialized objects in
1799 member-initializer-lists. For example, GCC warns about ``b`` being
1800 uninitialized in the following snippet:
1801
1802 .. code-block:: c++
1803
1804 struct A {
1805 int a;
1806 int b;
1807 A() : a(b) { }
1808 };
1809
1810.. option:: -Wno-uninitialized
1811
1812 Default setting; overrides :option:`-Wuninitialized`.
1813
1814.. option:: -Wno-invalid-memory-model
1815
1816 This option controls warnings
1817 for invocations of :ref:`atomic-builtins`, :ref:`sync-builtins`,
1818 and the C11 atomic generic functions with a memory consistency argument
1819 that is either invalid for the operation or outside the range of values
1820 of the ``memory_order`` enumeration. For example, since the
1821 ``__atomic_store`` and ``__atomic_store_n`` built-ins are only
1822 defined for the relaxed, release, and sequentially consistent memory
1823 orders the following code is diagnosed:
1824
1825 .. code-block:: c++
1826
1827 void store (int *i)
1828 {
1829 __atomic_store_n (i, 0, memory_order_consume);
1830 }
1831
1832 :option:`-Winvalid-memory-model` is enabled by default.
1833
1834.. option:: -Winvalid-memory-model
1835
1836 Default setting; overrides :option:`-Wno-invalid-memory-model`.
1837
1838.. option:: -Wmaybe-uninitialized
1839
1840 For an object with automatic or allocated storage duration, if there exists
1841 a path from the function entry to a use of the object that is initialized,
1842 but there exist some other paths for which the object is not initialized,
1843 the compiler emits a warning if it cannot prove the uninitialized paths
1844 are not executed at run time.
1845
1846 In addition, passing a pointer (or in C++, a reference) to an uninitialized
1847 object to a ``const`` -qualified function argument is also diagnosed by
1848 this warning. (:option:`-Wuninitialized` is issued for built-in functions
1849 known to read the object.) Annotating the function with attribute
1850 ``access (none)`` indicates that the argument isn't used to access
1851 the object and avoids the warning (see :ref:`common-function-attributes`).
1852
1853 These warnings are only possible in optimizing compilation, because otherwise
1854 GCC does not keep track of the state of variables.
1855
1856 These warnings are made optional because GCC may not be able to determine when
1857 the code is correct in spite of appearing to have an error. Here is one
1858 example of how this can happen:
1859
1860 .. code-block:: c++
1861
1862 {
1863 int x;
1864 switch (y)
1865 {
1866 case 1: x = 1;
1867 break;
1868 case 2: x = 4;
1869 break;
1870 case 3: x = 5;
1871 }
1872 foo (x);
1873 }
1874
1875 If the value of ``y`` is always 1, 2 or 3, then ``x`` is
1876 always initialized, but GCC doesn't know this. To suppress the
1877 warning, you need to provide a default case with assert(0) or
1878 similar code.
1879
1880 .. index:: longjmp warnings
1881
1882 This option also warns when a non-volatile automatic variable might be
1883 changed by a call to ``longjmp``.
1884 The compiler sees only the calls to ``setjmp``. It cannot know
1885 where ``longjmp`` will be called; in fact, a signal handler could
1886 call it at any point in the code. As a result, you may get a warning
1887 even when there is in fact no problem because ``longjmp`` cannot
1888 in fact be called at the place that would cause a problem.
1889
1890 Some spurious warnings can be avoided if you declare all the functions
1891 you use that never return as :fn-attr:`noreturn`. See :ref:`function-attributes`.
1892
1893 This warning is enabled by :option:`-Wall` or :option:`-Wextra`.
1894
1895.. option:: -Wno-maybe-uninitialized
1896
1897 Default setting; overrides :option:`-Wmaybe-uninitialized`.
1898
1899.. index:: warning for unknown pragmas, unknown pragmas, warning, pragmas, warning of unknown
1900
1901.. option:: -Wunknown-pragmas
1902
1903 Warn when a ``#pragma`` directive is encountered that is not understood by
1904 GCC. If this command-line option is used, warnings are even issued
1905 for unknown pragmas in system header files. This is not the case if
1906 the warnings are only enabled by the :option:`-Wall` command-line option.
1907
1908.. option:: -Wno-unknown-pragmas
1909
1910 Default setting; overrides :option:`-Wunknown-pragmas`.
1911
1912.. option:: -Wno-pragmas
1913
1914 Do not warn about misuses of pragmas, such as incorrect parameters,
1915 invalid syntax, or conflicts between pragmas. See also
1916 :option:`-Wunknown-pragmas`.
1917
1918.. option:: -Wpragmas
1919
1920 Default setting; overrides :option:`-Wno-pragmas`.
1921
1922.. option:: -Wno-prio-ctor-dtor
1923
1924 Do not warn if a priority from 0 to 100 is used for constructor or destructor.
1925 The use of constructor and destructor attributes allow you to assign a
1926 priority to the constructor/destructor to control its order of execution
1927 before ``main`` is called or after it returns. The priority values must be
1928 greater than 100 as the compiler reserves priority values between 0--100 for
1929 the implementation.
1930
1931.. option:: -Wprio-ctor-dtor
1932
1933 Default setting; overrides :option:`-Wno-prio-ctor-dtor`.
1934
1935.. option:: -Wstrict-aliasing
1936
1937 This option is only active when :option:`-fstrict-aliasing` is active.
1938 It warns about code that might break the strict aliasing rules that the
1939 compiler is using for optimization. The warning does not catch all
1940 cases, but does attempt to catch the more common pitfalls. It is
1941 included in :option:`-Wall`.
1942 It is equivalent to :option:`-Wstrict-aliasing=3`
1943
1944.. option:: -Wno-strict-aliasing
1945
1946 Default setting; overrides :option:`-Wstrict-aliasing`.
1947
1948.. option:: -Wstrict-aliasing=n
1949
1950 This option is only active when :option:`-fstrict-aliasing` is active.
1951 It warns about code that might break the strict aliasing rules that the
1952 compiler is using for optimization.
1953 Higher levels correspond to higher accuracy (fewer false positives).
1954 Higher levels also correspond to more effort, similar to the way :option:`-O`
1955 works.
1956 :option:`-Wstrict-aliasing` is equivalent to :option:`-Wstrict-aliasing=3`.
1957
1958 Level 1: Most aggressive, quick, least accurate.
1959 Possibly useful when higher levels
1960 do not warn but :option:`-fstrict-aliasing` still breaks the code, as it has very few
1961 false negatives. However, it has many false positives.
1962 Warns for all pointer conversions between possibly incompatible types,
1963 even if never dereferenced. Runs in the front end only.
1964
1965 Level 2: Aggressive, quick, not too precise.
1966 May still have many false positives (not as many as level 1 though),
1967 and few false negatives (but possibly more than level 1).
1968 Unlike level 1, it only warns when an address is taken. Warns about
1969 incomplete types. Runs in the front end only.
1970
1971 Level 3 (default for :option:`-Wstrict-aliasing`):
1972 Should have very few false positives and few false
1973 negatives. Slightly slower than levels 1 or 2 when optimization is enabled.
1974 Takes care of the common pun+dereference pattern in the front end:
1975 ``*(int*)&some_float``.
1976 If optimization is enabled, it also runs in the back end, where it deals
1977 with multiple statement cases using flow-sensitive points-to information.
1978 Only warns when the converted pointer is dereferenced.
1979 Does not warn about incomplete types.
1980
1981.. option:: -Wstrict-overflow, -Wstrict-overflow={n}
1982
1983 This option is only active when signed overflow is undefined.
1984 It warns about cases where the compiler optimizes based on the
1985 assumption that signed overflow does not occur. Note that it does not
1986 warn about all cases where the code might overflow: it only warns
1987 about cases where the compiler implements some optimization. Thus
1988 this warning depends on the optimization level.
1989
1990 An optimization that assumes that signed overflow does not occur is
1991 perfectly safe if the values of the variables involved are such that
1992 overflow never does, in fact, occur. Therefore this warning can
1993 easily give a false positive: a warning about code that is not
1994 actually a problem. To help focus on important issues, several
1995 warning levels are defined. No warnings are issued for the use of
1996 undefined signed overflow when estimating how many iterations a loop
1997 requires, in particular when determining whether a loop will be
1998 executed at all.
1999
2000 ``-Wstrict-overflow=1``
2001 Warn about cases that are both questionable and easy to avoid. For
2002 example the compiler simplifies
2003 ``x + 1 > x`` to ``1``. This level of
2004 :option:`-Wstrict-overflow` is enabled by :option:`-Wall` ; higher levels
2005 are not, and must be explicitly requested.
2006
2007 ``-Wstrict-overflow=2``
2008 Also warn about other cases where a comparison is simplified to a
2009 constant. For example: ``abs (x) >= 0``. This can only be
2010 simplified when signed integer overflow is undefined, because
2011 ``abs (INT_MIN)`` overflows to ``INT_MIN``, which is less than
2012 zero. :option:`-Wstrict-overflow` (with no level) is the same as
2013 :option:`-Wstrict-overflow=2`.
2014
2015 ``-Wstrict-overflow=3``
2016 Also warn about other cases where a comparison is simplified. For
2017 example: ``x + 1 > 1`` is simplified to ``x > 0``.
2018
2019 ``-Wstrict-overflow=4``
2020 Also warn about other simplifications not covered by the above cases.
2021 For example: ``(x * 10) / 5`` is simplified to ``x * 2``.
2022
2023 ``-Wstrict-overflow=5``
2024 Also warn about cases where the compiler reduces the magnitude of a
2025 constant involved in a comparison. For example: ``x + 2 > y`` is
2026 simplified to ``x + 1 >= y``. This is reported only at the
2027 highest warning level because this simplification applies to many
2028 comparisons, so this warning level gives a very large number of
2029 false positives.
2030
2031.. option:: -Wno-strict-overflow
2032
2033 Default setting; overrides :option:`-Wstrict-overflow`.
2034
2035.. option:: -Wstring-compare
2036
2037 Warn for calls to ``strcmp`` and ``strncmp`` whose result is
2038 determined to be either zero or non-zero in tests for such equality
2039 owing to the length of one argument being greater than the size of
2040 the array the other argument is stored in (or the bound in the case
2041 of ``strncmp``). Such calls could be mistakes. For example,
2042 the call to ``strcmp`` below is diagnosed because its result is
2043 necessarily non-zero irrespective of the contents of the array ``a``.
2044
2045 .. code-block:: c++
2046
2047 extern char a[4];
2048 void f (char *d)
2049 {
2050 strcpy (d, "string");
2051 ...
2052 if (0 == strcmp (a, d)) // cannot be true
2053 puts ("a and d are the same");
2054 }
2055
2056 :option:`-Wstring-compare` is enabled by :option:`-Wextra`.
2057
2058.. option:: -Wno-string-compare
2059
2060 Default setting; overrides :option:`-Wstring-compare`.
2061
2062.. option:: -Wstringop-overflow, -Wstringop-overflow={type}
2063
2064 Warn for calls to string manipulation functions such as ``memcpy`` and
2065 ``strcpy`` that are determined to overflow the destination buffer. The
2066 optional argument is one greater than the type of Object Size Checking to
2067 perform to determine the size of the destination. See :ref:`object-size-checking`.
2068 The argument is meaningful only for functions that operate on character arrays
2069 but not for raw memory functions like ``memcpy`` which always make use
2070 of Object Size type-0. The option also warns for calls that specify a size
2071 in excess of the largest possible object or at most ``SIZE_MAX / 2`` bytes.
2072 The option produces the best results with optimization enabled but can detect
2073 a small subset of simple buffer overflows even without optimization in
2074 calls to the GCC built-in functions like ``__builtin_memcpy`` that
2075 correspond to the standard functions. In any case, the option warns about
2076 just a subset of buffer overflows detected by the corresponding overflow
2077 checking built-ins. For example, the option issues a warning for
2078 the ``strcpy`` call below because it copies at least 5 characters
2079 (the string ``"blue"`` including the terminating NUL) into the buffer
2080 of size 4.
2081
2082 .. code-block:: c++
2083
2084 enum Color { blue, purple, yellow };
2085 const char* f (enum Color clr)
2086 {
2087 static char buf [4];
2088 const char *str;
2089 switch (clr)
2090 {
2091 case blue: str = "blue"; break;
2092 case purple: str = "purple"; break;
2093 case yellow: str = "yellow"; break;
2094 }
2095
2096 return strcpy (buf, str); // warning here
2097 }
2098
2099 Option :option:`-Wstringop-overflow=2` is enabled by default.
2100
2101 ``-Wstringop-overflow=1``
2102 The :option:`-Wstringop-overflow=1` option uses type-zero Object Size Checking
2103 to determine the sizes of destination objects. At this setting the option
2104 does not warn for writes past the end of subobjects of larger objects accessed
2105 by pointers unless the size of the largest surrounding object is known. When
2106 the destination may be one of several objects it is assumed to be the largest
2107 one of them. On Linux systems, when optimization is enabled at this setting
2108 the option warns for the same code as when the ``_FORTIFY_SOURCE`` macro
2109 is defined to a non-zero value.
2110
2111 ``-Wstringop-overflow=2``
2112 The :option:`-Wstringop-overflow=2` option uses type-one Object Size Checking
2113 to determine the sizes of destination objects. At this setting the option
2114 warns about overflows when writing to members of the largest complete
2115 objects whose exact size is known. However, it does not warn for excessive
2116 writes to the same members of unknown objects referenced by pointers since
2117 they may point to arrays containing unknown numbers of elements. This is
2118 the default setting of the option.
2119
2120 ``-Wstringop-overflow=3``
2121 The :option:`-Wstringop-overflow=3` option uses type-two Object Size Checking
2122 to determine the sizes of destination objects. At this setting the option
2123 warns about overflowing the smallest object or data member. This is the
2124 most restrictive setting of the option that may result in warnings for safe
2125 code.
2126
2127 ``-Wstringop-overflow=4``
2128 The :option:`-Wstringop-overflow=4` option uses type-three Object Size Checking
2129 to determine the sizes of destination objects. At this setting the option
2130 warns about overflowing any data members, and when the destination is
2131 one of several objects it uses the size of the largest of them to decide
2132 whether to issue a warning. Similarly to :option:`-Wstringop-overflow=3` this
2133 setting of the option may result in warnings for benign code.
2134
2135.. option:: -Wno-stringop-overflow
2136
2137 Default setting; overrides :option:`-Wstringop-overflow`.
2138
2139.. option:: -Wno-stringop-overread
2140
2141 Warn for calls to string manipulation functions such as ``memchr``, or
2142 ``strcpy`` that are determined to read past the end of the source
2143 sequence.
2144
2145 Option :option:`-Wstringop-overread` is enabled by default.
2146
2147.. option:: -Wstringop-overread
2148
2149 Default setting; overrides :option:`-Wno-stringop-overread`.
2150
2151.. option:: -Wno-stringop-truncation
2152
2153 Do not warn for calls to bounded string manipulation functions
2154 such as ``strncat``,
2155 ``strncpy``, and ``stpncpy`` that may either truncate the copied string
2156 or leave the destination unchanged.
2157
2158 In the following example, the call to ``strncat`` specifies a bound that
2159 is less than the length of the source string. As a result, the copy of
2160 the source will be truncated and so the call is diagnosed. To avoid the
2161 warning use ``bufsize - strlen (buf) - 1)`` as the bound.
2162
2163 .. code-block:: c++
2164
2165 void append (char *buf, size_t bufsize)
2166 {
2167 strncat (buf, ".txt", 3);
2168 }
2169
2170 As another example, the following call to ``strncpy`` results in copying
2171 to ``d`` just the characters preceding the terminating NUL, without
2172 appending the NUL to the end. Assuming the result of ``strncpy`` is
2173 necessarily a NUL-terminated string is a common mistake, and so the call
2174 is diagnosed. To avoid the warning when the result is not expected to be
2175 NUL-terminated, call ``memcpy`` instead.
2176
2177 .. code-block:: c++
2178
2179 void copy (char *d, const char *s)
2180 {
2181 strncpy (d, s, strlen (s));
2182 }
2183
2184 In the following example, the call to ``strncpy`` specifies the size
2185 of the destination buffer as the bound. If the length of the source
2186 string is equal to or greater than this size the result of the copy will
2187 not be NUL-terminated. Therefore, the call is also diagnosed. To avoid
2188 the warning, specify ``sizeof buf - 1`` as the bound and set the last
2189 element of the buffer to ``NUL``.
2190
2191 .. code-block:: c++
2192
2193 void copy (const char *s)
2194 {
2195 char buf[80];
2196 strncpy (buf, s, sizeof buf);
2197 ...
2198 }
2199
2200 In situations where a character array is intended to store a sequence
2201 of bytes with no terminating ``NUL`` such an array may be annotated
2202 with attribute :var-attr:`nonstring` to avoid this warning. Such arrays,
2203 however, are not suitable arguments to functions that expect
2204 ``NUL`` -terminated strings. To help detect accidental misuses of
2205 such arrays GCC issues warnings unless it can prove that the use is
2206 safe. See :ref:`common-variable-attributes`.
2207
2208.. option:: -Wstringop-truncation
2209
2210 Default setting; overrides :option:`-Wno-stringop-truncation`.
2211
2212.. option:: -Wsuggest-attribute=[pure|const|noreturn|format|cold|malloc]
2213
2214 Warn for cases where adding an attribute may be beneficial. The
2215 attributes currently supported are listed below.
2216
2217 .. option:: -Wsuggest-attribute=pure, -Wno-suggest-attribute=pure, -Wno-suggest-attribute=const, -Wno-suggest-attribute=noreturn, -Wno-missing-noreturn, -Wno-suggest-attribute=malloc
2218
2219 Warn about functions that might be candidates for attributes
2220 :fn-attr:`pure`, :fn-attr:`const` or :fn-attr:`noreturn` or ``malloc``. The compiler
2221 only warns for functions visible in other compilation units or (in the case of
2222 :fn-attr:`pure` and :fn-attr:`const`) if it cannot prove that the function returns
2223 normally. A function returns normally if it doesn't contain an infinite loop or
2224 return abnormally by throwing, calling ``abort`` or trapping. This analysis
2225 requires option :option:`-fipa-pure-const`, which is enabled by default at
2226 :option:`-O` and higher. Higher optimization levels improve the accuracy
2227 of the analysis.
2228
2229 .. option:: -Wsuggest-attribute=format, -Wno-suggest-attribute=format, -Wno-missing-format-attribute
2230
2231 Warn about function pointers that might be candidates for ``format``
2232 attributes. Note these are only possible candidates, not absolute ones.
2233 GCC guesses that function pointers with ``format`` attributes that
2234 are used in assignment, initialization, parameter passing or return
2235 statements should have a corresponding ``format`` attribute in the
2236 resulting type. I.e. the left-hand side of the assignment or
2237 initialization, the type of the parameter variable, or the return type
2238 of the containing function respectively should also have a ``format``
2239 attribute to avoid the warning.
2240
2241 GCC also warns about function definitions that might be
2242 candidates for ``format`` attributes. Again, these are only
2243 possible candidates. GCC guesses that ``format`` attributes
2244 might be appropriate for any function that calls a function like
2245 ``vprintf`` or ``vscanf``, but this might not always be the
2246 case, and some functions for which ``format`` attributes are
2247 appropriate may not be detected.
2248
2249 .. option:: -Wsuggest-attribute=cold
2250
2251 Warn about functions that might be candidates for :fn-attr:`cold` attribute. This
2252 is based on static detection and generally only warns about functions which
2253 always leads to a call to another :fn-attr:`cold` function such as wrappers of
2254 C++ ``throw`` or fatal error reporting functions leading to ``abort``.
2255
2256 .. option:: -Wno-suggest-attribute=cold
2257
2258 Default setting; overrides :option:`-Wsuggest-attribute=cold`.
2259
2260.. option:: -Walloc-zero
2261
2262 Warn about calls to allocation functions decorated with attribute
2263 ``alloc_size`` that specify zero bytes, including those to the built-in
2264 forms of the functions ``aligned_alloc``, ``alloca``, ``calloc``,
2265 ``malloc``, and ``realloc``. Because the behavior of these functions
2266 when called with a zero size differs among implementations (and in the case
2267 of ``realloc`` has been deprecated) relying on it may result in subtle
2268 portability bugs and should be avoided.
2269
2270.. option:: -Wno-alloc-zero
2271
2272 Default setting; overrides :option:`-Walloc-zero`.
2273
2274.. option:: -Walloc-size-larger-than={byte-size}
2275
2276 Warn about calls to functions decorated with attribute ``alloc_size``
2277 that attempt to allocate objects larger than the specified number of bytes,
2278 or where the result of the size computation in an integer type with infinite
2279 precision would exceed the value of :samp:`PTRDIFF_MAX` on the target.
2280 :option:`-Walloc-size-larger-than=PTRDIFF_MAX` is enabled by default.
2281 Warnings controlled by the option can be disabled either by specifying
2282 :samp:`{byte-size}` of :samp:`SIZE_MAX` or more or by
2283 :option:`-Wno-alloc-size-larger-than`.
2284 See :ref:`function-attributes`.
2285
2286.. option:: -Wno-alloc-size-larger-than
2287
2288 Disable :option:`-Walloc-size-larger-than=` warnings. The option is
2289 equivalent to :option:`-Walloc-size-larger-than=SIZE_MAX` or
2290 larger.
2291
2292.. option:: -Walloca
2293
2294 This option warns on all uses of ``alloca`` in the source.
2295
2296.. option:: -Wno-alloca
2297
2298 Default setting; overrides :option:`-Walloca`.
2299
2300.. option:: -Walloca-larger-than={byte-size}
2301
2302 This option warns on calls to ``alloca`` with an integer argument whose
2303 value is either zero, or that is not bounded by a controlling predicate
2304 that limits its value to at most :samp:`{byte-size}`. It also warns for calls
2305 to ``alloca`` where the bound value is unknown. Arguments of non-integer
2306 types are considered unbounded even if they appear to be constrained to
2307 the expected range.
2308
2309 For example, a bounded case of ``alloca`` could be:
2310
2311 .. code-block:: c++
2312
2313 void func (size_t n)
2314 {
2315 void *p;
2316 if (n <= 1000)
2317 p = alloca (n);
2318 else
2319 p = malloc (n);
2320 f (p);
2321 }
2322
2323 In the above example, passing ``-Walloca-larger-than=1000`` would not
2324 issue a warning because the call to ``alloca`` is known to be at most
2325 1000 bytes. However, if ``-Walloca-larger-than=500`` were passed,
2326 the compiler would emit a warning.
2327
2328 Unbounded uses, on the other hand, are uses of ``alloca`` with no
2329 controlling predicate constraining its integer argument. For example:
2330
2331 .. code-block:: c++
2332
2333 void func ()
2334 {
2335 void *p = alloca (n);
2336 f (p);
2337 }
2338
2339 If ``-Walloca-larger-than=500`` were passed, the above would trigger
2340 a warning, but this time because of the lack of bounds checking.
2341
2342 Note, that even seemingly correct code involving signed integers could
2343 cause a warning:
2344
2345 .. code-block:: c++
2346
2347 void func (signed int n)
2348 {
2349 if (n < 500)
2350 {
2351 p = alloca (n);
2352 f (p);
2353 }
2354 }
2355
2356 In the above example, :samp:`{n}` could be negative, causing a larger than
2357 expected argument to be implicitly cast into the ``alloca`` call.
2358
2359 This option also warns when ``alloca`` is used in a loop.
2360
2361 :option:`-Walloca-larger-than=PTRDIFF_MAX` is enabled by default
2362 but is usually only effective when :option:`-ftree-vrp` is active (default
2363 for :option:`-O2` and above).
2364
2365 See also :option:`-Wvla-larger-than=byte-size`.
2366
2367.. option:: -Wno-alloca-larger-than
2368
2369 Disable :option:`-Walloca-larger-than=` warnings. The option is
2370 equivalent to :option:`-Walloca-larger-than=SIZE_MAX` or larger.
2371
2372.. option:: -Warith-conversion
2373
2374 Do warn about implicit conversions from arithmetic operations even
2375 when conversion of the operands to the same type cannot change their
2376 values. This affects warnings from :option:`-Wconversion`,
2377 :option:`-Wfloat-conversion`, and :option:`-Wsign-conversion`.
2378
2379 .. code-block:: c++
2380
2381 void f (char c, int i)
2382 {
2383 c = c + i; // warns with -Wconversion
2384 c = c + 1; // only warns with -Warith-conversion
2385 }
2386
2387.. option:: -Wno-arith-conversion
2388
2389 Default setting; overrides :option:`-Warith-conversion`.
2390
2391.. option:: -Warray-bounds, -Warray-bounds={n}
2392
2393 Warn about out of bounds subscripts or offsets into arrays. This warning
2394 is enabled by :option:`-Wall`. It is more effective when :option:`-ftree-vrp`
2395 is active (the default for :option:`-O2` and above) but a subset of instances
2396 are issued even without optimization.
2397
2398 ``-Warray-bounds=1``
2399 This is the default warning level of :option:`-Warray-bounds` and is enabled
2400 by :option:`-Wall` ; higher levels are not, and must be explicitly requested.
2401
2402 ``-Warray-bounds=2``
2403 This warning level also warns about out of bounds accesses to trailing
2404 struct members of one-element array types (see :ref:`zero-length`) and about
2405 the intermediate results of pointer arithmetic that may yield out of bounds
2406 values. This warning level may give a larger number of false positives and
2407 is deactivated by default.
2408
2409.. option:: -Wno-array-bounds
2410
2411 Default setting; overrides :option:`-Warray-bounds`.
2412
2413.. option:: -Warray-compare
2414
2415 Warn about equality and relational comparisons between two operands of array
2416 type. This comparison was deprecated in C++20. For example:
2417
2418 .. code-block:: c++
2419
2420 int arr1[5];
2421 int arr2[5];
2422 bool same = arr1 == arr2;
2423
2424 :option:`-Warray-compare` is enabled by :option:`-Wall`.
2425
2426.. option:: -Wno-array-compare
2427
2428 Default setting; overrides :option:`-Warray-compare`.
2429
2430.. option:: -Warray-parameter, -Warray-parameter={n}
2431
2432 Warn about redeclarations of functions involving arguments of array or
2433 pointer types of inconsistent kinds or forms, and enable the detection
2434 of out-of-bounds accesses to such parameters by warnings such as
2435 :option:`-Warray-bounds`.
2436
2437 If the first function declaration uses the array form the bound specified
2438 in the array is assumed to be the minimum number of elements expected to
2439 be provided in calls to the function and the maximum number of elements
2440 accessed by it. Failing to provide arguments of sufficient size or accessing
2441 more than the maximum number of elements may be diagnosed by warnings such
2442 as :option:`-Warray-bounds`. At level 1 the warning diagnoses inconsistencies
2443 involving array parameters declared using the ``T[static N]`` form.
2444
2445 For example, the warning triggers for the following redeclarations because
2446 the first one allows an array of any size to be passed to ``f`` while
2447 the second one with the keyword ``static`` specifies that the array
2448 argument must have at least four elements.
2449
2450 .. code-block:: c++
2451
2452 void f (int[static 4]);
2453 void f (int[]); // warning (inconsistent array form)
2454
2455 void g (void)
2456 {
2457 int *p = (int *)malloc (4);
2458 f (p); // warning (array too small)
2459 ...
2460 }
2461
2462 At level 2 the warning also triggers for redeclarations involving any other
2463 inconsistency in array or pointer argument forms denoting array sizes.
2464 Pointers and arrays of unspecified bound are considered equivalent and do
2465 not trigger a warning.
2466
2467 .. code-block:: c++
2468
2469 void g (int*);
2470 void g (int[]); // no warning
2471 void g (int[8]); // warning (inconsistent array bound)
2472
2473 :option:`-Warray-parameter=2` is included in :option:`-Wall`. The
2474 :option:`-Wvla-parameter` option triggers warnings for similar inconsistencies
2475 involving Variable Length Array arguments.
2476
2477.. option:: -Wno-array-parameter
2478
2479 Default setting; overrides :option:`-Warray-parameter`.
2480
2481.. option:: -Wattribute-alias={n}
2482
2483 Warn about declarations using the ``alias`` and similar attributes whose
2484 target is incompatible with the type of the alias.
2485 See :ref:`function-attributes`.
2486
2487 ``-Wattribute-alias=1``
2488 The default warning level of the :option:`-Wattribute-alias` option diagnoses
2489 incompatibilities between the type of the alias declaration and that of its
2490 target. Such incompatibilities are typically indicative of bugs.
2491
2492 ``-Wattribute-alias=2``
2493 At this level :option:`-Wattribute-alias` also diagnoses cases where
2494 the attributes of the alias declaration are more restrictive than the
2495 attributes applied to its target. These mismatches can potentially
2496 result in incorrect code generation. In other cases they may be
2497 benign and could be resolved simply by adding the missing attribute to
2498 the target. For comparison, see the :option:`-Wmissing-attributes`
2499 option, which controls diagnostics when the alias declaration is less
2500 restrictive than the target, rather than more restrictive.
2501
2502 Attributes considered include ``alloc_align``, ``alloc_size``,
2503 :fn-attr:`cold`, :fn-attr:`const`, :fn-attr:`hot`, :fn-attr:`leaf`, :fn-attr:`malloc`,
2504 :fn-attr:`nonnull`, :fn-attr:`noreturn`, :fn-attr:`nothrow`, :fn-attr:`pure`,
2505 :fn-attr:`returns_nonnull`, and :fn-attr:`returns_twice`.
2506
2507 :option:`-Wattribute-alias` is equivalent to :option:`-Wattribute-alias=1`.
2508 This is the default. You can disable these warnings with either
2509 :option:`-Wno-attribute-alias` or :option:`-Wattribute-alias=0`.
2510
2511.. option:: -Wattribute-alias
2512
2513 Default setting; overrides :option:`-Wno-attribute-alias`.
2514
2515.. option:: -Wbidi-chars=[none|unpaired|any|ucn]
2516
2517 Warn about possibly misleading UTF-8 bidirectional control characters in
2518 comments, string literals, character constants, and identifiers. Such
2519 characters can change left-to-right writing direction into right-to-left
2520 (and vice versa), which can cause confusion between the logical order and
2521 visual order. This may be dangerous; for instance, it may seem that a piece
2522 of code is not commented out, whereas it in fact is.
2523
2524 There are three levels of warning supported by GCC. The default is
2525 :option:`-Wbidi-chars=unpaired`, which warns about improperly terminated
2526 bidi contexts. :option:`-Wbidi-chars=none` turns the warning off.
2527 :option:`-Wbidi-chars=any` warns about any use of bidirectional control
2528 characters.
2529
2530 By default, this warning does not warn about UCNs. It is, however, possible
2531 to turn on such checking by using :option:`-Wbidi-chars=unpaired,ucn` or
2532 :option:`-Wbidi-chars=any,ucn`. Using :option:`-Wbidi-chars=ucn` is valid,
2533 and is equivalent to :option:`-Wbidi-chars=unpaired,ucn`, if no previous
2534 :option:`-Wbidi-chars=any` was specified.
2535
2536.. option:: -Wbool-compare
2537
2538 Warn about boolean expression compared with an integer value different from
2539 ``true`` / ``false``. For instance, the following comparison is
2540 always false:
2541
2542 .. code-block:: c++
2543
2544 int n = 5;
2545 ...
2546 if ((n > 1) == 2) { ... }
2547
2548 This warning is enabled by :option:`-Wall`.
2549
2550.. option:: -Wno-bool-compare
2551
2552 Default setting; overrides :option:`-Wbool-compare`.
2553
2554.. option:: -Wbool-operation
2555
2556 Warn about suspicious operations on expressions of a boolean type. For
2557 instance, bitwise negation of a boolean is very likely a bug in the program.
2558 For C, this warning also warns about incrementing or decrementing a boolean,
2559 which rarely makes sense. (In C++, decrementing a boolean is always invalid.
2560 Incrementing a boolean is invalid in C++17, and deprecated otherwise.)
2561
2562 This warning is enabled by :option:`-Wall`.
2563
2564.. option:: -Wno-bool-operation
2565
2566 Default setting; overrides :option:`-Wbool-operation`.
2567
2568.. option:: -Wduplicated-branches
2569
2570 Warn when an if-else has identical branches. This warning detects cases like
2571
2572 .. code-block:: c++
2573
2574 if (p != NULL)
2575 return 0;
2576 else
2577 return 0;
2578
2579 It doesn't warn when both branches contain just a null statement. This warning
2580 also warn for conditional operators:
2581
2582 .. code-block:: c++
2583
2584 int i = x ? *p : *p;
2585
2586.. option:: -Wno-duplicated-branches
2587
2588 Default setting; overrides :option:`-Wduplicated-branches`.
2589
2590.. option:: -Wduplicated-cond
2591
2592 Warn about duplicated conditions in an if-else-if chain. For instance,
2593 warn for the following code:
2594
2595 .. code-block:: c++
2596
2597 if (p->q != NULL) { ... }
2598 else if (p->q != NULL) { ... }
2599
2600.. option:: -Wno-duplicated-cond
2601
2602 Default setting; overrides :option:`-Wduplicated-cond`.
2603
2604.. option:: -Wframe-address
2605
2606 Warn when the :samp:`__builtin_frame_address` or :samp:`__builtin_return_address`
2607 is called with an argument greater than 0. Such calls may return indeterminate
2608 values or crash the program. The warning is included in :option:`-Wall`.
2609
2610.. option:: -Wno-frame-address
2611
2612 Default setting; overrides :option:`-Wframe-address`.
2613
2614.. option:: -Wno-discarded-qualifiers
2615
2616 .. note::
2617
2618 C and Objective-C only
2619
2620 Do not warn if type qualifiers on pointers are being discarded.
2621 Typically, the compiler warns if a ``const char *`` variable is
2622 passed to a function that takes a ``char *`` parameter. This option
2623 can be used to suppress such a warning.
2624
2625.. option:: -Wdiscarded-qualifiers
2626
2627 Default setting; overrides :option:`-Wno-discarded-qualifiers`.
2628
2629.. option:: -Wno-discarded-array-qualifiers
2630
2631 .. note::
2632
2633 C and Objective-C only
2634
2635 Do not warn if type qualifiers on arrays which are pointer targets
2636 are being discarded. Typically, the compiler warns if a
2637 ``const int (*)[]`` variable is passed to a function that
2638 takes a ``int (*)[]`` parameter. This option can be used to
2639 suppress such a warning.
2640
2641.. option:: -Wdiscarded-array-qualifiers
2642
2643 Default setting; overrides :option:`-Wno-discarded-array-qualifiers`.
2644
2645.. option:: -Wno-incompatible-pointer-types
2646
2647 .. note::
2648
2649 C and Objective-C only
2650
2651 Do not warn when there is a conversion between pointers that have incompatible
2652 types. This warning is for cases not covered by :option:`-Wno-pointer-sign`,
2653 which warns for pointer argument passing or assignment with different
2654 signedness.
2655
2656.. option:: -Wincompatible-pointer-types
2657
2658 Default setting; overrides :option:`-Wno-incompatible-pointer-types`.
2659
2660.. option:: -Wno-int-conversion
2661
2662 .. note::
2663
2664 C and Objective-C only
2665
2666 Do not warn about incompatible integer to pointer and pointer to integer
2667 conversions. This warning is about implicit conversions; for explicit
2668 conversions the warnings :option:`-Wno-int-to-pointer-cast` and
2669 :option:`-Wno-pointer-to-int-cast` may be used.
2670
2671.. option:: -Wint-conversion
2672
2673 Default setting; overrides :option:`-Wno-int-conversion`.
2674
2675.. option:: -Wzero-length-bounds
2676
2677 Warn about accesses to elements of zero-length array members that might
2678 overlap other members of the same object. Declaring interior zero-length
2679 arrays is discouraged because accesses to them are undefined. See
2680 See :ref:`zero-length`.
2681
2682 For example, the first two stores in function ``bad`` are diagnosed
2683 because the array elements overlap the subsequent members ``b`` and
2684 ``c``. The third store is diagnosed by :option:`-Warray-bounds`
2685 because it is beyond the bounds of the enclosing object.
2686
2687 .. code-block:: c++
2688
2689 struct X { int a[0]; int b, c; };
2690 struct X x;
2691
2692 void bad (void)
2693 {
2694 x.a[0] = 0; // -Wzero-length-bounds
2695 x.a[1] = 1; // -Wzero-length-bounds
2696 x.a[2] = 2; // -Warray-bounds
2697 }
2698
2699 Option :option:`-Wzero-length-bounds` is enabled by :option:`-Warray-bounds`.
2700
2701.. option:: -Wno-div-by-zero
2702
2703 Do not warn about compile-time integer division by zero. Floating-point
2704 division by zero is not warned about, as it can be a legitimate way of
2705 obtaining infinities and NaNs.
2706
2707.. option:: -Wdiv-by-zero
2708
2709 Default setting; overrides :option:`-Wno-div-by-zero`.
2710
2711.. index:: warnings from system headers, system headers, warnings from
2712
2713.. option:: -Wsystem-headers
2714
2715 Print warning messages for constructs found in system header files.
2716 Warnings from system headers are normally suppressed, on the assumption
2717 that they usually do not indicate real problems and would only make the
2718 compiler output harder to read. Using this command-line option tells
2719 GCC to emit warnings from system headers as if they occurred in user
2720 code. However, note that using :option:`-Wall` in conjunction with this
2721 option does *not* warn about unknown pragmas in system
2722 headers --- for that, :option:`-Wunknown-pragmas` must also be used.
2723
2724.. option:: -Wno-system-headers
2725
2726 Default setting; overrides :option:`-Wsystem-headers`.
2727
2728.. option:: -Wtautological-compare
2729
2730 Warn if a self-comparison always evaluates to true or false. This
2731 warning detects various mistakes such as:
2732
2733 .. code-block:: c++
2734
2735 int i = 1;
2736 ...
2737 if (i > i) { ... }
2738
2739 This warning also warns about bitwise comparisons that always evaluate
2740 to true or false, for instance:
2741
2742 .. code-block:: c++
2743
2744 if ((a & 16) == 10) { ... }
2745
2746 will always be false.
2747
2748 This warning is enabled by :option:`-Wall`.
2749
2750.. option:: -Wno-tautological-compare
2751
2752 Default setting; overrides :option:`-Wtautological-compare`.
2753
2754.. option:: -Wtrampolines
2755
2756 Warn about trampolines generated for pointers to nested functions.
2757 A trampoline is a small piece of data or code that is created at run
2758 time on the stack when the address of a nested function is taken, and is
2759 used to call the nested function indirectly. For some targets, it is
2760 made up of data only and thus requires no special treatment. But, for
2761 most targets, it is made up of code and thus requires the stack to be
2762 made executable in order for the program to work properly.
2763
2764.. option:: -Wno-trampolines
2765
2766 Default setting; overrides :option:`-Wtrampolines`.
2767
2768.. option:: -Wfloat-equal
2769
2770 Warn if floating-point values are used in equality comparisons.
2771
2772 The idea behind this is that sometimes it is convenient (for the
2773 programmer) to consider floating-point values as approximations to
2774 infinitely precise real numbers. If you are doing this, then you need
2775 to compute (by analyzing the code, or in some other way) the maximum or
2776 likely maximum error that the computation introduces, and allow for it
2777 when performing comparisons (and when producing output, but that's a
2778 different problem). In particular, instead of testing for equality, you
2779 should check to see whether the two values have ranges that overlap; and
2780 this is done with the relational operators, so equality comparisons are
2781 probably mistaken.
2782
2783.. option:: -Wno-float-equal
2784
2785 Default setting; overrides :option:`-Wfloat-equal`.
2786
2787.. option:: -Wtraditional
2788
2789 .. note::
2790
2791 C and Objective-C only
2792
2793 Warn about certain constructs that behave differently in traditional and
2794 ISO C. Also warn about ISO C constructs that have no traditional C
2795 equivalent, and/or problematic constructs that should be avoided.
2796
2797 * Macro parameters that appear within string literals in the macro body.
2798 In traditional C macro replacement takes place within string literals,
2799 but in ISO C it does not.
2800
2801 * In traditional C, some preprocessor directives did not exist.
2802 Traditional preprocessors only considered a line to be a directive
2803 if the :samp:`#` appeared in column 1 on the line. Therefore
2804 :option:`-Wtraditional` warns about directives that traditional C
2805 understands but ignores because the :samp:`#` does not appear as the
2806 first character on the line. It also suggests you hide directives like
2807 ``#pragma`` not understood by traditional C by indenting them. Some
2808 traditional implementations do not recognize ``#elif``, so this option
2809 suggests avoiding it altogether.
2810
2811 * A function-like macro that appears without arguments.
2812
2813 * The unary plus operator.
2814
2815 * The :samp:`U` integer constant suffix, or the :samp:`F` or :samp:`L` floating-point
2816 constant suffixes. (Traditional C does support the :samp:`L` suffix on integer
2817 constants.) Note, these suffixes appear in macros defined in the system
2818 headers of most modern systems, e.g. the :samp:`_MIN`/:samp:`_MAX` macros in ``<limits.h>``.
2819 Use of these macros in user code might normally lead to spurious
2820 warnings, however GCC's integrated preprocessor has enough context to
2821 avoid warning in these cases.
2822
2823 * A function declared external in one block and then used after the end of
2824 the block.
2825
2826 * A ``switch`` statement has an operand of type ``long``.
2827
2828 * A non- ``static`` function declaration follows a ``static`` one.
2829 This construct is not accepted by some traditional C compilers.
2830
2831 * The ISO type of an integer constant has a different width or
2832 signedness from its traditional type. This warning is only issued if
2833 the base of the constant is ten. I.e. hexadecimal or octal values, which
2834 typically represent bit patterns, are not warned about.
2835
2836 * Usage of ISO string concatenation is detected.
2837
2838 * Initialization of automatic aggregates.
2839
2840 * Identifier conflicts with labels. Traditional C lacks a separate
2841 namespace for labels.
2842
2843 * Initialization of unions. If the initializer is zero, the warning is
2844 omitted. This is done under the assumption that the zero initializer in
2845 user code appears conditioned on e.g. ``__STDC__`` to avoid missing
2846 initializer warnings and relies on default initialization to zero in the
2847 traditional C case.
2848
2849 * Conversions by prototypes between fixed/floating-point values and vice
2850 versa. The absence of these prototypes when compiling with traditional
2851 C causes serious problems. This is a subset of the possible
2852 conversion warnings; for the full set use :option:`-Wtraditional-conversion`.
2853
2854 * Use of ISO C style function definitions. This warning intentionally is
2855 *not* issued for prototype declarations or variadic functions
2856 because these ISO C features appear in your code when using
2857 libiberty's traditional C compatibility macros, ``PARAMS`` and
2858 ``VPARAMS``. This warning is also bypassed for nested functions
2859 because that feature is already a GCC extension and thus not relevant to
2860 traditional C compatibility.
2861
2862.. option:: -Wno-traditional
2863
2864 Default setting; overrides :option:`-Wtraditional`.
2865
2866.. option:: -Wtraditional-conversion
2867
2868 .. note::
2869
2870 C and Objective-C only
2871
2872 Warn if a prototype causes a type conversion that is different from what
2873 would happen to the same argument in the absence of a prototype. This
2874 includes conversions of fixed point to floating and vice versa, and
2875 conversions changing the width or signedness of a fixed-point argument
2876 except when the same as the default promotion.
2877
2878.. option:: -Wno-traditional-conversion
2879
2880 Default setting; overrides :option:`-Wtraditional-conversion`.
2881
2882.. option:: -Wdeclaration-after-statement
2883
2884 .. note::
2885
2886 C and Objective-C only
2887
2888 Warn when a declaration is found after a statement in a block. This
2889 construct, known from C++, was introduced with ISO C99 and is by default
2890 allowed in GCC. It is not supported by ISO C90. See :ref:`mixed-labels-and-declarations`.
2891
2892.. option:: -Wno-declaration-after-statement
2893
2894 Default setting; overrides :option:`-Wdeclaration-after-statement`.
2895
2896.. option:: -Wshadow
2897
2898 Warn whenever a local variable or type declaration shadows another
2899 variable, parameter, type, class member (in C++), or instance variable
2900 (in Objective-C) or whenever a built-in function is shadowed. Note
2901 that in C++, the compiler warns if a local variable shadows an
2902 explicit typedef, but not if it shadows a struct/class/enum.
2903 If this warning is enabled, it includes also all instances of
2904 local shadowing. This means that :option:`-Wno-shadow=local`
2905 and :option:`-Wno-shadow=compatible-local` are ignored when
2906 :option:`-Wshadow` is used.
2907 Same as :option:`-Wshadow=global`.
2908
2909.. option:: -Wno-shadow
2910
2911 Default setting; overrides :option:`-Wshadow`.
2912
2913.. option:: -Wno-shadow-ivar
2914
2915 .. note::
2916
2917 Objective-C only
2918
2919 Do not warn whenever a local variable shadows an instance variable in an
2920 Objective-C method.
2921
2922.. option:: -Wshadow-ivar
2923
2924 Default setting; overrides :option:`-Wno-shadow-ivar`.
2925
2926.. option:: -Wshadow=global
2927
2928 Warn for any shadowing.
2929 Same as :option:`-Wshadow`.
2930
2931.. option:: -Wshadow=local
2932
2933 Warn when a local variable shadows another local variable or parameter.
2934
2935.. option:: -Wshadow=compatible-local
2936
2937 Warn when a local variable shadows another local variable or parameter
2938 whose type is compatible with that of the shadowing variable. In C++,
2939 type compatibility here means the type of the shadowing variable can be
2940 converted to that of the shadowed variable. The creation of this flag
2941 (in addition to :option:`-Wshadow=local`) is based on the idea that when
2942 a local variable shadows another one of incompatible type, it is most
2943 likely intentional, not a bug or typo, as shown in the following example:
2944
2945 .. code-block:: c++
2946
2947 for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
2948 {
2949 for (int i = 0; i < N; ++i)
2950 {
2951 ...
2952 }
2953 ...
2954 }
2955
2956 Since the two variable ``i`` in the example above have incompatible types,
2957 enabling only :option:`-Wshadow=compatible-local` does not emit a warning.
2958 Because their types are incompatible, if a programmer accidentally uses one
2959 in place of the other, type checking is expected to catch that and emit an
2960 error or warning. Use of this flag instead of :option:`-Wshadow=local` can
2961 possibly reduce the number of warnings triggered by intentional shadowing.
2962 Note that this also means that shadowing ``const char *i`` by
2963 ``char *i`` does not emit a warning.
2964
2965 This warning is also enabled by :option:`-Wshadow=local`.
2966
2967.. index:: Wlarger-than-byte-size
2968
2969.. option:: -Wlarger-than={byte-size}
2970
2971 Warn whenever an object is defined whose size exceeds :samp:`{byte-size}`.
2972 :option:`-Wlarger-than=PTRDIFF_MAX` is enabled by default.
2973 Warnings controlled by the option can be disabled either by specifying
2974 :samp:`{byte-size}` of :samp:`SIZE_MAX` or more or by :option:`-Wno-larger-than`.
2975
2976 Also warn for calls to bounded functions such as ``memchr`` or
2977 ``strnlen`` that specify a bound greater than the largest possible
2978 object, which is :samp:`PTRDIFF_MAX` bytes by default. These warnings
2979 can only be disabled by :option:`-Wno-larger-than`.
2980
2981.. option:: -Wno-larger-than
2982
2983 Disable :option:`-Wlarger-than=` warnings. The option is equivalent
2984 to :option:`-Wlarger-than=SIZE_MAX` or larger.
2985
2986.. option:: -Wframe-larger-than={byte-size}
2987
2988 Warn if the size of a function frame exceeds :samp:`{byte-size}`.
2989 The computation done to determine the stack frame size is approximate
2990 and not conservative.
2991 The actual requirements may be somewhat greater than :samp:`{byte-size}`
2992 even if you do not get a warning. In addition, any space allocated
2993 via ``alloca``, variable-length arrays, or related constructs
2994 is not included by the compiler when determining
2995 whether or not to issue a warning.
2996 :option:`-Wframe-larger-than=PTRDIFF_MAX` is enabled by default.
2997 Warnings controlled by the option can be disabled either by specifying
2998 :samp:`{byte-size}` of :samp:`SIZE_MAX` or more or by
2999 :option:`-Wno-frame-larger-than`.
3000
3001.. option:: -Wno-frame-larger-than
3002
3003 Disable :option:`-Wframe-larger-than=` warnings. The option is equivalent
3004 to :option:`-Wframe-larger-than=SIZE_MAX` or larger.
3005
3006.. option:: -Wfree-nonheap-object
3007
3008 Warn when attempting to deallocate an object that was either not allocated
3009 on the heap, or by using a pointer that was not returned from a prior call
3010 to the corresponding allocation function. For example, because the call
3011 to ``stpcpy`` returns a pointer to the terminating nul character and
3012 not to the beginning of the object, the call to ``free`` below is
3013 diagnosed.
3014
3015 .. code-block:: c++
3016
3017 void f (char *p)
3018 {
3019 p = stpcpy (p, "abc");
3020 // ...
3021 free (p); // warning
3022 }
3023
3024 :option:`-Wfree-nonheap-object` is included in :option:`-Wall`.
3025
3026.. option:: -Wno-free-nonheap-object
3027
3028 Default setting; overrides :option:`-Wfree-nonheap-object`.
3029
3030.. option:: -Wstack-usage={byte-size}
3031
3032 Warn if the stack usage of a function might exceed :samp:`{byte-size}`.
3033 The computation done to determine the stack usage is conservative.
3034 Any space allocated via ``alloca``, variable-length arrays, or related
3035 constructs is included by the compiler when determining whether or not to
3036 issue a warning.
3037
3038 The message is in keeping with the output of :option:`-fstack-usage`.
3039
3040 * If the stack usage is fully static but exceeds the specified amount, it's:
3041
3042 .. code-block:: c++
3043
3044 warning: stack usage is 1120 bytes
3045
3046 * If the stack usage is (partly) dynamic but bounded, it's:
3047
3048 .. code-block:: c++
3049
3050 warning: stack usage might be 1648 bytes
3051
3052 * If the stack usage is (partly) dynamic and not bounded, it's:
3053
3054 .. code-block:: c++
3055
3056 warning: stack usage might be unbounded
3057
3058 :option:`-Wstack-usage=PTRDIFF_MAX` is enabled by default.
3059 Warnings controlled by the option can be disabled either by specifying
3060 :samp:`{byte-size}` of :samp:`SIZE_MAX` or more or by
3061 :option:`-Wno-stack-usage`.
3062
3063.. option:: -Wno-stack-usage
3064
3065 Disable :option:`-Wstack-usage=` warnings. The option is equivalent
3066 to :option:`-Wstack-usage=SIZE_MAX` or larger.
3067
3068.. option:: -Wunsafe-loop-optimizations
3069
3070 Warn if the loop cannot be optimized because the compiler cannot
3071 assume anything on the bounds of the loop indices. With
3072 :option:`-funsafe-loop-optimizations` warn if the compiler makes
3073 such assumptions.
3074
3075.. option:: -Wno-unsafe-loop-optimizations
3076
3077 Default setting; overrides :option:`-Wunsafe-loop-optimizations`.
3078
3079.. option:: -Wno-pedantic-ms-format
3080
3081 .. note::
3082
3083 MinGW targets only
3084
3085 When used in combination with :option:`-Wformat`
3086 and :option:`-pedantic` without GNU extensions, this option
3087 disables the warnings about non-ISO ``printf`` / ``scanf`` format
3088 width specifiers ``I32``, ``I64``, and ``I`` used on Windows targets,
3089 which depend on the MS runtime.
3090
3091.. option:: -Wpedantic-ms-format
3092
3093 Default setting; overrides :option:`-Wno-pedantic-ms-format`.
3094
3095.. option:: -Wpointer-arith
3096
3097 Warn about anything that depends on the 'size of' a function type or
3098 of ``void``. GNU C assigns these types a size of 1, for
3099 convenience in calculations with ``void *`` pointers and pointers
3100 to functions. In C++, warn also when an arithmetic operation involves
3101 ``NULL``. This warning is also enabled by :option:`-Wpedantic`.
3102
3103.. option:: -Wno-pointer-arith
3104
3105 Default setting; overrides :option:`-Wpointer-arith`.
3106
3107.. option:: -Wno-pointer-compare
3108
3109 Do not warn if a pointer is compared with a zero character constant.
3110 This usually
3111 means that the pointer was meant to be dereferenced. For example:
3112
3113 .. code-block:: c++
3114
3115 const char *p = foo ();
3116 if (p == '\0')
3117 return 42;
3118
3119 Note that the code above is invalid in C++11.
3120
3121 This warning is enabled by default.
3122
3123.. option:: -Wpointer-compare
3124
3125 Default setting; overrides :option:`-Wno-pointer-compare`.
3126
3127.. option:: -Wtsan
3128
3129 Warn about unsupported features in ThreadSanitizer.
3130
3131 ThreadSanitizer does not support ``std::atomic_thread_fence`` and
3132 can report false positives.
3133
3134 This warning is enabled by default.
3135
3136.. option:: -Wno-tsan
3137
3138 Default setting; overrides :option:`-Wtsan`.
3139
3140.. option:: -Wtype-limits
3141
3142 Warn if a comparison is always true or always false due to the limited
3143 range of the data type, but do not warn for constant expressions. For
3144 example, warn if an unsigned variable is compared against zero with
3145 ``<`` or ``>=``. This warning is also enabled by
3146 :option:`-Wextra`.
3147
3148.. option:: -Wno-type-limits
3149
3150 Default setting; overrides :option:`-Wtype-limits`.
3151
3152.. option:: -Wabsolute-value
3153
3154 .. note::
3155
3156 C and Objective-C only
3157
3158 Warn for calls to standard functions that compute the absolute value
3159 of an argument when a more appropriate standard function is available.
3160 For example, calling ``abs(3.14)`` triggers the warning because the
3161 appropriate function to call to compute the absolute value of a double
3162 argument is ``fabs``. The option also triggers warnings when the
3163 argument in a call to such a function has an unsigned type. This
3164 warning can be suppressed with an explicit type cast and it is also
3165 enabled by :option:`-Wextra`.
3166
3167.. option:: -Wno-absolute-value
3168
3169 Default setting; overrides :option:`-Wabsolute-value`.
3170
3171.. include:: ../../../../doc/cppwarnopts.rst
3172
3173
3174.. option:: -Wendif-labels
3175
3176 Default setting; overrides :option:`-Wno-endif-labels`.
3177
3178.. option:: -Wbad-function-cast
3179
3180 .. note::
3181
3182 C and Objective-C only
3183
3184 Warn when a function call is cast to a non-matching type.
3185 For example, warn if a call to a function returning an integer type
3186 is cast to a pointer type.
3187
3188.. option:: -Wno-bad-function-cast
3189
3190 Default setting; overrides :option:`-Wbad-function-cast`.
3191
3192.. option:: -Wc90-c99-compat
3193
3194 .. note::
3195
3196 C and Objective-C only
3197
3198 Warn about features not present in ISO C90, but present in ISO C99.
3199 For instance, warn about use of variable length arrays, ``long long``
3200 type, ``bool`` type, compound literals, designated initializers, and so
3201 on. This option is independent of the standards mode. Warnings are disabled
3202 in the expression that follows ``__extension__``.
3203
3204.. option:: -Wno-c90-c99-compat
3205
3206 Default setting; overrides :option:`-Wc90-c99-compat`.
3207
3208.. option:: -Wc99-c11-compat
3209
3210 .. note::
3211
3212 C and Objective-C only
3213
3214 Warn about features not present in ISO C99, but present in ISO C11.
3215 For instance, warn about use of anonymous structures and unions,
3216 ``_Atomic`` type qualifier, ``_Thread_local`` storage-class specifier,
3217 ``_Alignas`` specifier, ``Alignof`` operator, ``_Generic`` keyword,
3218 and so on. This option is independent of the standards mode. Warnings are
3219 disabled in the expression that follows ``__extension__``.
3220
3221.. option:: -Wno-c99-c11-compat
3222
3223 Default setting; overrides :option:`-Wc99-c11-compat`.
3224
3225.. option:: -Wc11-c2x-compat
3226
3227 .. note::
3228
3229 C and Objective-C only
3230
3231 Warn about features not present in ISO C11, but present in ISO C2X.
3232 For instance, warn about omitting the string in ``_Static_assert``,
3233 use of :samp:`[[]]` syntax for attributes, use of decimal
3234 floating-point types, and so on. This option is independent of the
3235 standards mode. Warnings are disabled in the expression that follows
3236 ``__extension__``.
3237
3238.. option:: -Wno-c11-c2x-compat
3239
3240 Default setting; overrides :option:`-Wc11-c2x-compat`.
3241
3242.. option:: -Wc++-compat
3243
3244 .. note::
3245
3246 C and Objective-C only
3247
3248 Warn about ISO C constructs that are outside of the common subset of
3249 ISO C and ISO C++, e.g. request for implicit conversion from
3250 ``void *`` to a pointer to non- ``void`` type.
3251
3252.. option:: -Wno-c++-compat
3253
3254 Default setting; overrides :option:`-Wc++-compat`.
3255
3256.. option:: -Wc++11-compat
3257
3258 .. note::
3259
3260 C++ and Objective-C++ only
3261
3262 Warn about C++ constructs whose meaning differs between ISO C++ 1998
3263 and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are keywords
3264 in ISO C++ 2011. This warning turns on :option:`-Wnarrowing` and is
3265 enabled by :option:`-Wall`.
3266
3267.. option:: -Wno-c++11-compat
3268
3269 Default setting; overrides :option:`-Wc++11-compat`.
3270
3271.. option:: -Wc++14-compat
3272
3273 .. note::
3274
3275 C++ and Objective-C++ only
3276
3277 Warn about C++ constructs whose meaning differs between ISO C++ 2011
3278 and ISO C++ 2014. This warning is enabled by :option:`-Wall`.
3279
3280.. option:: -Wno-c++14-compat
3281
3282 Default setting; overrides :option:`-Wc++14-compat`.
3283
3284.. option:: -Wc++17-compat
3285
3286 .. note::
3287
3288 C++ and Objective-C++ only
3289
3290 Warn about C++ constructs whose meaning differs between ISO C++ 2014
3291 and ISO C++ 2017. This warning is enabled by :option:`-Wall`.
3292
3293.. option:: -Wno-c++17-compat
3294
3295 Default setting; overrides :option:`-Wc++17-compat`.
3296
3297.. option:: -Wc++20-compat
3298
3299 .. note::
3300
3301 C++ and Objective-C++ only
3302
3303 Warn about C++ constructs whose meaning differs between ISO C++ 2017
3304 and ISO C++ 2020. This warning is enabled by :option:`-Wall`.
3305
3306.. option:: -Wno-c++20-compat
3307
3308 Default setting; overrides :option:`-Wc++20-compat`.
3309
3310.. option:: -Wno-c++11-extensions
3311
3312 .. note::
3313
3314 C++ and Objective-C++ only
3315
3316 Do not warn about C++11 constructs in code being compiled using
3317 an older C++ standard. Even without this option, some C++11 constructs
3318 will only be diagnosed if :option:`-Wpedantic` is used.
3319
3320.. option:: -Wc++11-extensions
3321
3322 Default setting; overrides :option:`-Wno-c++11-extensions`.
3323
3324.. option:: -Wno-c++14-extensions
3325
3326 .. note::
3327
3328 C++ and Objective-C++ only
3329
3330 Do not warn about C++14 constructs in code being compiled using
3331 an older C++ standard. Even without this option, some C++14 constructs
3332 will only be diagnosed if :option:`-Wpedantic` is used.
3333
3334.. option:: -Wc++14-extensions
3335
3336 Default setting; overrides :option:`-Wno-c++14-extensions`.
3337
3338.. option:: -Wno-c++17-extensions
3339
3340 .. note::
3341
3342 C++ and Objective-C++ only
3343
3344 Do not warn about C++17 constructs in code being compiled using
3345 an older C++ standard. Even without this option, some C++17 constructs
3346 will only be diagnosed if :option:`-Wpedantic` is used.
3347
3348.. option:: -Wc++17-extensions
3349
3350 Default setting; overrides :option:`-Wno-c++17-extensions`.
3351
3352.. option:: -Wno-c++20-extensions
3353
3354 .. note::
3355
3356 C++ and Objective-C++ only
3357
3358 Do not warn about C++20 constructs in code being compiled using
3359 an older C++ standard. Even without this option, some C++20 constructs
3360 will only be diagnosed if :option:`-Wpedantic` is used.
3361
3362.. option:: -Wc++20-extensions
3363
3364 Default setting; overrides :option:`-Wno-c++20-extensions`.
3365
3366.. option:: -Wno-c++23-extensions
3367
3368 .. note::
3369
3370 C++ and Objective-C++ only
3371
3372 Do not warn about C++23 constructs in code being compiled using
3373 an older C++ standard. Even without this option, some C++23 constructs
3374 will only be diagnosed if :option:`-Wpedantic` is used.
3375
3376.. option:: -Wc++23-extensions
3377
3378 Default setting; overrides :option:`-Wno-c++23-extensions`.
3379
3380.. option:: -Wcast-qual
3381
3382 Warn whenever a pointer is cast so as to remove a type qualifier from
3383 the target type. For example, warn if a ``const char *`` is cast
3384 to an ordinary ``char *``.
3385
3386 Also warn when making a cast that introduces a type qualifier in an
3387 unsafe way. For example, casting ``char **`` to ``const char **``
3388 is unsafe, as in this example:
3389
3390 .. code-block:: c++
3391
3392 /* p is char ** value. */
3393 const char **q = (const char **) p;
3394 /* Assignment of readonly string to const char * is OK. */
3395 *q = "string";
3396 /* Now char** pointer points to read-only memory. */
3397 **p = 'b';
3398
3399.. option:: -Wno-cast-qual
3400
3401 Default setting; overrides :option:`-Wcast-qual`.
3402
3403.. option:: -Wcast-align
3404
3405 Warn whenever a pointer is cast such that the required alignment of the
3406 target is increased. For example, warn if a ``char *`` is cast to
3407 an ``int *`` on machines where integers can only be accessed at
3408 two- or four-byte boundaries.
3409
3410.. option:: -Wno-cast-align
3411
3412 Default setting; overrides :option:`-Wcast-align`.
3413
3414.. option:: -Wcast-align=strict
3415
3416 Warn whenever a pointer is cast such that the required alignment of the
3417 target is increased. For example, warn if a ``char *`` is cast to
3418 an ``int *`` regardless of the target machine.
3419
3420.. option:: -Wcast-function-type
3421
3422 Warn when a function pointer is cast to an incompatible function pointer.
3423 In a cast involving function types with a variable argument list only
3424 the types of initial arguments that are provided are considered.
3425 Any parameter of pointer-type matches any other pointer-type. Any benign
3426 differences in integral types are ignored, like ``int`` vs. ``long``
3427 on ILP32 targets. Likewise type qualifiers are ignored. The function
3428 type ``void (*) (void)`` is special and matches everything, which can
3429 be used to suppress this warning.
3430 In a cast involving pointer to member types this warning warns whenever
3431 the type cast is changing the pointer to member type.
3432 This warning is enabled by :option:`-Wextra`.
3433
3434.. option:: -Wno-cast-function-type
3435
3436 Default setting; overrides :option:`-Wcast-function-type`.
3437
3438.. option:: -Wwrite-strings
3439
3440 When compiling C, give string constants the type ``const
3441 char[length]`` so that copying the address of one into a
3442 non- ``const`` ``char *`` pointer produces a warning. These
3443 warnings help you find at compile time code that can try to write
3444 into a string constant, but only if you have been very careful about
3445 using ``const`` in declarations and prototypes. Otherwise, it is
3446 just a nuisance. This is why we did not make :option:`-Wall` request
3447 these warnings.
3448
3449 When compiling C++, warn about the deprecated conversion from string
3450 literals to ``char *``. This warning is enabled by default for C++
3451 programs.
3452
3453.. option:: -Wno-write-strings
3454
3455 Default setting; overrides :option:`-Wwrite-strings`.
3456
3457.. option:: -Wclobbered
3458
3459 Warn for variables that might be changed by ``longjmp`` or
3460 ``vfork``. This warning is also enabled by :option:`-Wextra`.
3461
3462.. option:: -Wno-clobbered
3463
3464 Default setting; overrides :option:`-Wclobbered`.
3465
3466.. option:: -Wconversion
3467
3468 Warn for implicit conversions that may alter a value. This includes
3469 conversions between real and integer, like ``abs (x)`` when
3470 ``x`` is ``double`` ; conversions between signed and unsigned,
3471 like ``unsigned ui = -1`` ; and conversions to smaller types, like
3472 ``sqrtf (M_PI)``. Do not warn for explicit casts like ``abs
3473 ((int) x)`` and ``ui = (unsigned) -1``, or if the value is not
3474 changed by the conversion like in ``abs (2.0)``. Warnings about
3475 conversions between signed and unsigned integers can be disabled by
3476 using :option:`-Wno-sign-conversion`.
3477
3478 For C++, also warn for confusing overload resolution for user-defined
3479 conversions; and conversions that never use a type conversion
3480 operator: conversions to ``void``, the same type, a base class or a
3481 reference to them. Warnings about conversions between signed and
3482 unsigned integers are disabled by default in C++ unless
3483 :option:`-Wsign-conversion` is explicitly enabled.
3484
3485 Warnings about conversion from arithmetic on a small type back to that
3486 type are only given with :option:`-Warith-conversion`.
3487
3488.. option:: -Wno-conversion
3489
3490 Default setting; overrides :option:`-Wconversion`.
3491
3492.. option:: -Wdangling-else
3493
3494 Warn about constructions where there may be confusion to which
3495 ``if`` statement an ``else`` branch belongs. Here is an example of
3496 such a case:
3497
3498 .. code-block:: c++
3499
3500 {
3501 if (a)
3502 if (b)
3503 foo ();
3504 else
3505 bar ();
3506 }
3507
3508 In C/C++, every ``else`` branch belongs to the innermost possible
3509 ``if`` statement, which in this example is ``if (b)``. This is
3510 often not what the programmer expected, as illustrated in the above
3511 example by indentation the programmer chose. When there is the
3512 potential for this confusion, GCC issues a warning when this flag
3513 is specified. To eliminate the warning, add explicit braces around
3514 the innermost ``if`` statement so there is no way the ``else``
3515 can belong to the enclosing ``if``. The resulting code
3516 looks like this:
3517
3518 .. code-block:: c++
3519
3520 {
3521 if (a)
3522 {
3523 if (b)
3524 foo ();
3525 else
3526 bar ();
3527 }
3528 }
3529
3530 This warning is enabled by :option:`-Wparentheses`.
3531
3532.. option:: -Wno-dangling-else
3533
3534 Default setting; overrides :option:`-Wdangling-else`.
3535
3536.. option:: -Wdangling-pointer, -Wdangling-pointer={n}
3537
3538 Warn about uses of pointers (or C++ references) to objects with automatic
3539 storage duration after their lifetime has ended. This includes local
3540 variables declared in nested blocks, compound literals and other unnamed
3541 temporary objects. In addition, warn about storing the address of such
3542 objects in escaped pointers. The warning is enabled at all optimization
3543 levels but may yield different results with optimization than without.
3544
3545 ``-Wdangling-pointer=1``
3546 At level 1 the warning diagnoses only unconditional uses of dangling pointers.
3547 For example
3548
3549 .. code-block:: c++
3550
3551 int f (int c1, int c2, x)
3552 {
3553 char *p = strchr ((char[]){ c1, c2 }, c3);
3554 return p ? *p : 'x'; // warning: dangling pointer to a compound literal
3555 }
3556
3557 In the following function the store of the address of the local variable
3558 ``x`` in the escaped pointer ``*p`` also triggers the warning.
3559
3560 .. code-block:: c++
3561
3562 void g (int **p)
3563 {
3564 int x = 7;
3565 *p = &x; // warning: storing the address of a local variable in *p
3566 }
3567
3568 ``-Wdangling-pointer=2``
3569 At level 2, in addition to unconditional uses the warning also diagnoses
3570 conditional uses of dangling pointers.
3571
3572 For example, because the array :samp:`{a}` in the following function is out of
3573 scope when the pointer :samp:`{s}` that was set to point is used, the warning
3574 triggers at this level.
3575
3576 .. code-block:: c++
3577
3578 void f (char *s)
3579 {
3580 if (!s)
3581 {
3582 char a[12] = "tmpname";
3583 s = a;
3584 }
3585 strcat (s, ".tmp"); // warning: dangling pointer to a may be used
3586 ...
3587 }
3588
3589 :option:`-Wdangling-pointer=2` is included in :option:`-Wall`.
3590
3591.. option:: -Wno-dangling-pointer
3592
3593 Default setting; overrides :option:`-Wdangling-pointer`.
3594
3595.. option:: -Wdate-time
3596
3597 Warn when macros ``__TIME__``, ``__DATE__`` or ``__TIMESTAMP__``
3598 are encountered as they might prevent bit-wise-identical reproducible
3599 compilations.
3600
3601.. option:: -Wno-date-time
3602
3603 Default setting; overrides :option:`-Wdate-time`.
3604
3605.. option:: -Wempty-body
3606
3607 Warn if an empty body occurs in an ``if``, ``else`` or ``do
3608 while`` statement. This warning is also enabled by :option:`-Wextra`.
3609
3610.. option:: -Wno-empty-body
3611
3612 Default setting; overrides :option:`-Wempty-body`.
3613
3614.. option:: -Wno-endif-labels
3615
3616 Do not warn about stray tokens after ``#else`` and ``#endif``.
3617
3618.. option:: -Wendif-labels
3619
3620 Default setting; overrides :option:`-Wno-endif-labels`.
3621
3622.. option:: -Wenum-compare
3623
3624 Warn about a comparison between values of different enumerated types.
3625 In C++ enumerated type mismatches in conditional expressions are also
3626 diagnosed and the warning is enabled by default. In C this warning is
3627 enabled by :option:`-Wall`.
3628
3629.. option:: -Wno-enum-compare
3630
3631 Default setting; overrides :option:`-Wenum-compare`.
3632
3633.. option:: -Wenum-conversion
3634
3635 Warn when a value of enumerated type is implicitly converted to a
3636 different enumerated type. This warning is enabled by :option:`-Wextra`
3637 in C.
3638
3639.. option:: -Wno-enum-conversion
3640
3641 Default setting; overrides :option:`-Wenum-conversion`.
3642
3643.. option:: -Wenum-int-mismatch
3644
3645 .. note::
3646
3647 C and Objective-C only
3648
3649 Warn about mismatches between an enumerated type and an integer type in
3650 declarations. For example:
3651
3652 .. code-block:: c++
3653
3654 enum E { l = -1, z = 0, g = 1 };
3655 int foo(void);
3656 enum E foo(void);
3657
3658 In C, an enumerated type is compatible with ``char``, a signed
3659 integer type, or an unsigned integer type. However, since the choice
3660 of the underlying type of an enumerated type is implementation-defined,
3661 such mismatches may cause portability issues. In C++, such mismatches
3662 are an error. In C, this warning is enabled by :option:`-Wall` and
3663 :option:`-Wc++-compat`.
3664
3665.. option:: -Wno-enum-int-mismatch
3666
3667 Default setting; overrides :option:`-Wenum-int-mismatch`.
3668
3669.. option:: -Wjump-misses-init
3670
3671 .. note::
3672
3673 C, Objective-C only
3674
3675 Warn if a ``goto`` statement or a ``switch`` statement jumps
3676 forward across the initialization of a variable, or jumps backward to a
3677 label after the variable has been initialized. This only warns about
3678 variables that are initialized when they are declared. This warning is
3679 only supported for C and Objective-C; in C++ this sort of branch is an
3680 error in any case.
3681
3682 :option:`-Wjump-misses-init` is included in :option:`-Wc++-compat`. It
3683 can be disabled with the :option:`-Wno-jump-misses-init` option.
3684
3685.. option:: -Wno-jump-misses-init
3686
3687 Default setting; overrides :option:`-Wjump-misses-init`.
3688
3689.. index:: warning for comparison of signed and unsigned values, comparison of signed and unsigned values, warning, signed and unsigned values, comparison warning
3690
3691.. option:: -Wsign-compare
3692
3693 Warn when a comparison between signed and unsigned values could produce
3694 an incorrect result when the signed value is converted to unsigned.
3695 In C++, this warning is also enabled by :option:`-Wall`. In C, it is
3696 also enabled by :option:`-Wextra`.
3697
3698.. option:: -Wno-sign-compare
3699
3700 Default setting; overrides :option:`-Wsign-compare`.
3701
3702.. option:: -Wsign-conversion
3703
3704 Warn for implicit conversions that may change the sign of an integer
3705 value, like assigning a signed integer expression to an unsigned
3706 integer variable. An explicit cast silences the warning. In C, this
3707 option is enabled also by :option:`-Wconversion`.
3708
3709.. option:: -Wno-sign-conversion
3710
3711 Default setting; overrides :option:`-Wsign-conversion`.
3712
3713.. option:: -Wfloat-conversion
3714
3715 Warn for implicit conversions that reduce the precision of a real value.
3716 This includes conversions from real to integer, and from higher precision
3717 real to lower precision real values. This option is also enabled by
3718 :option:`-Wconversion`.
3719
3720.. option:: -Wno-float-conversion
3721
3722 Default setting; overrides :option:`-Wfloat-conversion`.
3723
3724.. option:: -Wno-scalar-storage-order
3725
3726 Do not warn on suspicious constructs involving reverse scalar storage order.
3727
3728.. option:: -Wscalar-storage-order
3729
3730 Default setting; overrides :option:`-Wno-scalar-storage-order`.
3731
3732.. option:: -Wsizeof-array-div
3733
3734 Warn about divisions of two sizeof operators when the first one is applied
3735 to an array and the divisor does not equal the size of the array element.
3736 In such a case, the computation will not yield the number of elements in the
3737 array, which is likely what the user intended. This warning warns e.g. about
3738
3739 .. code-block:: c++
3740
3741 int fn ()
3742 {
3743 int arr[10];
3744 return sizeof (arr) / sizeof (short);
3745 }
3746
3747 This warning is enabled by :option:`-Wall`.
3748
3749.. option:: -Wno-sizeof-array-div
3750
3751 Default setting; overrides :option:`-Wsizeof-array-div`.
3752
3753.. option:: -Wsizeof-pointer-div
3754
3755 Warn for suspicious divisions of two sizeof expressions that divide
3756 the pointer size by the element size, which is the usual way to compute
3757 the array size but won't work out correctly with pointers. This warning
3758 warns e.g. about ``sizeof (ptr) / sizeof (ptr[0])`` if ``ptr`` is
3759 not an array, but a pointer. This warning is enabled by :option:`-Wall`.
3760
3761.. option:: -Wno-sizeof-pointer-div
3762
3763 Default setting; overrides :option:`-Wsizeof-pointer-div`.
3764
3765.. option:: -Wsizeof-pointer-memaccess
3766
3767 Warn for suspicious length parameters to certain string and memory built-in
3768 functions if the argument uses ``sizeof``. This warning triggers for
3769 example for ``memset (ptr, 0, sizeof (ptr));`` if ``ptr`` is not
3770 an array, but a pointer, and suggests a possible fix, or about
3771 ``memcpy (&foo, ptr, sizeof (&foo));``. :option:`-Wsizeof-pointer-memaccess`
3772 also warns about calls to bounded string copy functions like ``strncat``
3773 or ``strncpy`` that specify as the bound a ``sizeof`` expression of
3774 the source array. For example, in the following function the call to
3775 ``strncat`` specifies the size of the source string as the bound. That
3776 is almost certainly a mistake and so the call is diagnosed.
3777
3778 .. code-block:: c++
3779
3780 void make_file (const char *name)
3781 {
3782 char path[PATH_MAX];
3783 strncpy (path, name, sizeof path - 1);
3784 strncat (path, ".text", sizeof ".text");
3785 ...
3786 }
3787
3788 The :option:`-Wsizeof-pointer-memaccess` option is enabled by :option:`-Wall`.
3789
3790.. option:: -Wno-sizeof-pointer-memaccess
3791
3792 Default setting; overrides :option:`-Wsizeof-pointer-memaccess`.
3793
3794.. option:: -Wno-sizeof-array-argument
3795
3796 Do not warn when the ``sizeof`` operator is applied to a parameter that is
3797 declared as an array in a function definition. This warning is enabled by
3798 default for C and C++ programs.
3799
3800.. option:: -Wsizeof-array-argument
3801
3802 Default setting; overrides :option:`-Wno-sizeof-array-argument`.
3803
3804.. option:: -Wmemset-elt-size
3805
3806 Warn for suspicious calls to the ``memset`` built-in function, if the
3807 first argument references an array, and the third argument is a number
3808 equal to the number of elements, but not equal to the size of the array
3809 in memory. This indicates that the user has omitted a multiplication by
3810 the element size. This warning is enabled by :option:`-Wall`.
3811
3812.. option:: -Wno-memset-elt-size
3813
3814 Default setting; overrides :option:`-Wmemset-elt-size`.
3815
3816.. option:: -Wmemset-transposed-args
3817
3818 Warn for suspicious calls to the ``memset`` built-in function where
3819 the second argument is not zero and the third argument is zero. For
3820 example, the call ``memset (buf, sizeof buf, 0)`` is diagnosed because
3821 ``memset (buf, 0, sizeof buf)`` was meant instead. The diagnostic
3822 is only emitted if the third argument is a literal zero. Otherwise, if
3823 it is an expression that is folded to zero, or a cast of zero to some
3824 type, it is far less likely that the arguments have been mistakenly
3825 transposed and no warning is emitted. This warning is enabled
3826 by :option:`-Wall`.
3827
3828.. option:: -Wno-memset-transposed-args
3829
3830 Default setting; overrides :option:`-Wmemset-transposed-args`.
3831
3832.. option:: -Waddress
3833
3834 Warn about suspicious uses of address expressions. These include comparing
3835 the address of a function or a declared object to the null pointer constant
3836 such as in
3837
3838 .. code-block:: c++
3839
3840 void f (void);
3841 void g (void)
3842 {
3843 if (!f) // warning: expression evaluates to false
3844 abort ();
3845 }
3846
3847 comparisons of a pointer to a string literal, such as in
3848
3849 .. code-block:: c++
3850
3851 void f (const char *x)
3852 {
3853 if (x == "abc") // warning: expression evaluates to false
3854 puts ("equal");
3855 }
3856
3857 and tests of the results of pointer addition or subtraction for equality
3858 to null, such as in
3859
3860 .. code-block:: c++
3861
3862 void f (const int *p, int i)
3863 {
3864 return p + i == NULL;
3865 }
3866
3867 Such uses typically indicate a programmer error: the address of most
3868 functions and objects necessarily evaluates to true (the exception are
3869 weak symbols), so their use in a conditional might indicate missing
3870 parentheses in a function call or a missing dereference in an array
3871 expression. The subset of the warning for object pointers can be
3872 suppressed by casting the pointer operand to an integer type such
3873 as ``intptr_t`` or ``uintptr_t``.
3874 Comparisons against string literals result in unspecified behavior
3875 and are not portable, and suggest the intent was to call ``strcmp``.
3876 The warning is suppressed if the suspicious expression is the result
3877 of macro expansion.
3878 :option:`-Waddress` warning is enabled by :option:`-Wall`.
3879
3880.. option:: -Wno-address
3881
3882 Default setting; overrides :option:`-Waddress`.
3883
3884.. option:: -Wno-address-of-packed-member
3885
3886 Do not warn when the address of packed member of struct or union is taken,
3887 which usually results in an unaligned pointer value. This is
3888 enabled by default.
3889
3890.. option:: -Waddress-of-packed-member
3891
3892 Default setting; overrides :option:`-Wno-address-of-packed-member`.
3893
3894.. option:: -Wlogical-op
3895
3896 Warn about suspicious uses of logical operators in expressions.
3897 This includes using logical operators in contexts where a
3898 bit-wise operator is likely to be expected. Also warns when
3899 the operands of a logical operator are the same:
3900
3901 .. code-block:: c++
3902
3903 extern int a;
3904 if (a < 0 && a < 0) { ... }
3905
3906.. option:: -Wno-logical-op
3907
3908 Default setting; overrides :option:`-Wlogical-op`.
3909
3910.. option:: -Wlogical-not-parentheses
3911
3912 Warn about logical not used on the left hand side operand of a comparison.
3913 This option does not warn if the right operand is considered to be a boolean
3914 expression. Its purpose is to detect suspicious code like the following:
3915
3916 .. code-block:: c++
3917
3918 int a;
3919 ...
3920 if (!a > 1) { ... }
3921
3922 It is possible to suppress the warning by wrapping the LHS into
3923 parentheses:
3924
3925 .. code-block:: c++
3926
3927 if ((!a) > 1) { ... }
3928
3929 This warning is enabled by :option:`-Wall`.
3930
3931.. option:: -Wno-logical-not-parentheses
3932
3933 Default setting; overrides :option:`-Wlogical-not-parentheses`.
3934
3935.. option:: -Waggregate-return
3936
3937 Warn if any functions that return structures or unions are defined or
3938 called. (In languages where you can return an array, this also elicits
3939 a warning.)
3940
3941.. option:: -Wno-aggregate-return
3942
3943 Default setting; overrides :option:`-Waggregate-return`.
3944
3945.. option:: -Wno-aggressive-loop-optimizations
3946
3947 Warn if in a loop with constant number of iterations the compiler detects
3948 undefined behavior in some statement during one or more of the iterations.
3949
3950.. option:: -Waggressive-loop-optimizations
3951
3952 Default setting; overrides :option:`-Wno-aggressive-loop-optimizations`.
3953
3954.. option:: -Wno-attributes
3955
3956 Do not warn if an unexpected ``__attribute__`` is used, such as
3957 unrecognized attributes, function attributes applied to variables,
3958 etc. This does not stop errors for incorrect use of supported
3959 attributes.
3960
3961 Additionally, using :option:`-Wno-attributes=`, it is possible to suppress
3962 warnings about unknown scoped attributes (in C++11 and C2X). For example,
3963 :option:`-Wno-attributes=vendor::attr` disables warning about the following
3964 declaration:
3965
3966 .. code-block:: c++
3967
3968 [[vendor::attr]] void f();
3969
3970 It is also possible to disable warning about all attributes in a namespace
3971 using :option:`-Wno-attributes=vendor::` which prevents warning about both
3972 of these declarations:
3973
3974 .. code-block:: c++
3975
3976 [[vendor::safe]] void f();
3977 [[vendor::unsafe]] void f2();
3978
3979 Note that :option:`-Wno-attributes=` does not imply :option:`-Wno-attributes`.
3980
3981.. option:: -Wattributes
3982
3983 Default setting; overrides :option:`-Wno-attributes`.
3984
3985.. option:: -Wno-builtin-declaration-mismatch
3986
3987 Warn if a built-in function is declared with an incompatible signature
3988 or as a non-function, or when a built-in function declared with a type
3989 that does not include a prototype is called with arguments whose promoted
3990 types do not match those expected by the function. When :option:`-Wextra`
3991 is specified, also warn when a built-in function that takes arguments is
3992 declared without a prototype. The :option:`-Wbuiltin-declaration-mismatch`
3993 warning is enabled by default. To avoid the warning include the appropriate
3994 header to bring the prototypes of built-in functions into scope.
3995
3996 For example, the call to ``memset`` below is diagnosed by the warning
3997 because the function expects a value of type ``size_t`` as its argument
3998 but the type of ``32`` is ``int``. With :option:`-Wextra`,
3999 the declaration of the function is diagnosed as well.
4000
4001 .. code-block:: c++
4002
4003 extern void* memset ();
4004 void f (void *d)
4005 {
4006 memset (d, '\0', 32);
4007 }
4008
4009.. option:: -Wbuiltin-declaration-mismatch
4010
4011 Default setting; overrides :option:`-Wno-builtin-declaration-mismatch`.
4012
4013.. option:: -Wno-builtin-macro-redefined
4014
4015 Do not warn if certain built-in macros are redefined. This suppresses
4016 warnings for redefinition of ``__TIMESTAMP__``, ``__TIME__``,
4017 ``__DATE__``, ``__FILE__``, and ``__BASE_FILE__``.
4018
4019.. option:: -Wbuiltin-macro-redefined
4020
4021 Default setting; overrides :option:`-Wno-builtin-macro-redefined`.
4022
4023.. option:: -Wstrict-prototypes
4024
4025 .. note::
4026
4027 C and Objective-C only
4028
4029 Warn if a function is declared or defined without specifying the
4030 argument types. (An old-style function definition is permitted without
4031 a warning if preceded by a declaration that specifies the argument
4032 types.)
4033
4034.. option:: -Wno-strict-prototypes
4035
4036 Default setting; overrides :option:`-Wstrict-prototypes`.
4037
4038.. option:: -Wold-style-declaration
4039
4040 .. note::
4041
4042 C and Objective-C only
4043
4044 Warn for obsolescent usages, according to the C Standard, in a
4045 declaration. For example, warn if storage-class specifiers like
4046 ``static`` are not the first things in a declaration. This warning
4047 is also enabled by :option:`-Wextra`.
4048
4049.. option:: -Wno-old-style-declaration
4050
4051 Default setting; overrides :option:`-Wold-style-declaration`.
4052
4053.. option:: -Wold-style-definition
4054
4055 .. note::
4056
4057 C and Objective-C only
4058
4059 Warn if an old-style function definition is used. A warning is given
4060 even if there is a previous prototype. A definition using :samp:`()`
4061 is not considered an old-style definition in C2X mode, because it is
4062 equivalent to :samp:`(void)` in that case, but is considered an
4063 old-style definition for older standards.
4064
4065.. option:: -Wno-old-style-definition
4066
4067 Default setting; overrides :option:`-Wold-style-definition`.
4068
4069.. option:: -Wmissing-parameter-type
4070
4071 .. note::
4072
4073 C and Objective-C only
4074
4075 A function parameter is declared without a type specifier in K&R-style
4076 functions:
4077
4078 .. code-block:: c++
4079
4080 void foo(bar) { }
4081
4082 This warning is also enabled by :option:`-Wextra`.
4083
4084.. option:: -Wno-missing-parameter-type
4085
4086 Default setting; overrides :option:`-Wmissing-parameter-type`.
4087
4088.. option:: -Wmissing-prototypes
4089
4090 .. note::
4091
4092 C and Objective-C only
4093
4094 Warn if a global function is defined without a previous prototype
4095 declaration. This warning is issued even if the definition itself
4096 provides a prototype. Use this option to detect global functions
4097 that do not have a matching prototype declaration in a header file.
4098 This option is not valid for C++ because all function declarations
4099 provide prototypes and a non-matching declaration declares an
4100 overload rather than conflict with an earlier declaration.
4101 Use :option:`-Wmissing-declarations` to detect missing declarations in C++.
4102
4103.. option:: -Wno-missing-prototypes
4104
4105 Default setting; overrides :option:`-Wmissing-prototypes`.
4106
4107.. option:: -Wmissing-declarations
4108
4109 Warn if a global function is defined without a previous declaration.
4110 Do so even if the definition itself provides a prototype.
4111 Use this option to detect global functions that are not declared in
4112 header files. In C, no warnings are issued for functions with previous
4113 non-prototype declarations; use :option:`-Wmissing-prototypes` to detect
4114 missing prototypes. In C++, no warnings are issued for function templates,
4115 or for inline functions, or for functions in anonymous namespaces.
4116
4117.. option:: -Wno-missing-declarations
4118
4119 Default setting; overrides :option:`-Wmissing-declarations`.
4120
4121.. option:: -Wmissing-field-initializers
4122
4123 Warn if a structure's initializer has some fields missing. For
4124 example, the following code causes such a warning, because
4125 ``x.h`` is implicitly zero:
4126
4127 .. code-block:: c++
4128
4129 struct s { int f, g, h; };
4130 struct s x = { 3, 4 };
4131
4132 This option does not warn about designated initializers, so the following
4133 modification does not trigger a warning:
4134
4135 .. code-block:: c++
4136
4137 struct s { int f, g, h; };
4138 struct s x = { .f = 3, .g = 4 };
4139
4140 In C this option does not warn about the universal zero initializer
4141 :samp:`{ 0 }`:
4142
4143 .. code-block:: c++
4144
4145 struct s { int f, g, h; };
4146 struct s x = { 0 };
4147
4148 Likewise, in C++ this option does not warn about the empty { }
4149 initializer, for example:
4150
4151 .. code-block:: c++
4152
4153 struct s { int f, g, h; };
4154 s x = { };
4155
4156 This warning is included in :option:`-Wextra`. To get other :option:`-Wextra`
4157 warnings without this one, use :option:`-Wextra -Wno-missing-field-initializers`.
4158
4159.. option:: -Wno-missing-field-initializers
4160
4161 Default setting; overrides :option:`-Wmissing-field-initializers`.
4162
4163.. option:: -Wno-missing-requires
4164
4165 By default, the compiler warns about a concept-id appearing as a C++20 simple-requirement:
4166
4167 .. code-block:: c++
4168
4169 bool satisfied = requires { C<T> };
4170
4171 Here :samp:`satisfied` will be true if :samp:`C<T>` is a valid
4172 expression, which it is for all T. Presumably the user meant to write
4173
4174 .. code-block:: c++
4175
4176 bool satisfied = requires { requires C<T> };
4177
4178 so :samp:`satisfied` is only true if concept :samp:`C` is satisfied for
4179 type :samp:`T`.
4180
4181 This warning can be disabled with :option:`-Wno-missing-requires`.
4182
4183.. option:: -Wmissing-requires
4184
4185 Default setting; overrides :option:`-Wno-missing-requires`.
4186
4187.. option:: -Wno-missing-template-keyword
4188
4189 The member access tokens ., -> and :: must be followed by the ``template``
4190 keyword if the parent object is dependent and the member being named is a
4191 template.
4192
4193 .. code-block:: c++
4194
4195 template <class X>
4196 void DoStuff (X x)
4197 {
4198 x.template DoSomeOtherStuff<X>(); // Good.
4199 x.DoMoreStuff<X>(); // Warning, x is dependent.
4200 }
4201
4202 In rare cases it is possible to get false positives. To silence this, wrap
4203 the expression in parentheses. For example, the following is treated as a
4204 template, even where m and N are integers:
4205
4206 .. code-block:: c++
4207
4208 void NotATemplate (my_class t)
4209 {
4210 int N = 5;
4211
4212 bool test = t.m < N > (0); // Treated as a template.
4213 test = (t.m < N) > (0); // Same meaning, but not treated as a template.
4214 }
4215
4216 This warning can be disabled with :option:`-Wno-missing-template-keyword`.
4217
4218.. option:: -Wmissing-template-keyword
4219
4220 Default setting; overrides :option:`-Wno-missing-template-keyword`.
4221
4222.. option:: -Wno-multichar
4223
4224 Do not warn if a multicharacter constant (:samp:`'FOOF'`) is used.
4225 Usually they indicate a typo in the user's code, as they have
4226 implementation-defined values, and should not be used in portable code.
4227
4228.. option:: -Wmultichar
4229
4230 Default setting; overrides :option:`-Wno-multichar`.
4231
4232.. index:: NFC, NFKC, character set, input normalization
4233
4234.. option:: -Wnormalized=[none|id|nfc|nfkc]
4235
4236 In ISO C and ISO C++, two identifiers are different if they are
4237 different sequences of characters. However, sometimes when characters
4238 outside the basic ASCII character set are used, you can have two
4239 different character sequences that look the same. To avoid confusion,
4240 the ISO 10646 standard sets out some :dfn:`normalization rules` which
4241 when applied ensure that two sequences that look the same are turned into
4242 the same sequence. GCC can warn you if you are using identifiers that
4243 have not been normalized; this option controls that warning.
4244
4245 There are four levels of warning supported by GCC. The default is
4246 :option:`-Wnormalized=nfc`, which warns about any identifier that is
4247 not in the ISO 10646 'C' normalized form, :dfn:`NFC`. NFC is the
4248 recommended form for most uses. It is equivalent to
4249 :option:`-Wnormalized`.
4250
4251 Unfortunately, there are some characters allowed in identifiers by
4252 ISO C and ISO C++ that, when turned into NFC, are not allowed in
4253 identifiers. That is, there's no way to use these symbols in portable
4254 ISO C or C++ and have all your identifiers in NFC.
4255 :option:`-Wnormalized=id` suppresses the warning for these characters.
4256 It is hoped that future versions of the standards involved will correct
4257 this, which is why this option is not the default.
4258
4259 You can switch the warning off for all characters by writing
4260 :option:`-Wnormalized=none` or :option:`-Wno-normalized`. You should
4261 only do this if you are using some other normalization scheme (like
4262 'D'), because otherwise you can easily create bugs that are
4263 literally impossible to see.
4264
4265 Some characters in ISO 10646 have distinct meanings but look identical
4266 in some fonts or display methodologies, especially once formatting has
4267 been applied. For instance ``\u207F``, 'SUPERSCRIPT LATIN SMALL
4268 LETTER N', displays just like a regular ``n`` that has been
4269 placed in a superscript. ISO 10646 defines the :dfn:`NFKC`
4270 normalization scheme to convert all these into a standard form as
4271 well, and GCC warns if your code is not in NFKC if you use
4272 :option:`-Wnormalized=nfkc`. This warning is comparable to warning
4273 about every identifier that contains the letter O because it might be
4274 confused with the digit 0, and so is not the default, but may be
4275 useful as a local coding convention if the programming environment
4276 cannot be fixed to display these characters distinctly.
4277
4278.. option:: -Wno-attribute-warning
4279
4280 Do not warn about usage of functions (see :ref:`function-attributes`)
4281 declared with ``warning`` attribute. By default, this warning is
4282 enabled. :option:`-Wno-attribute-warning` can be used to disable the
4283 warning or :option:`-Wno-error=attribute-warning` can be used to
4284 disable the error when compiled with :option:`-Werror` flag.
4285
4286.. option:: -Wattribute-warning
4287
4288 Default setting; overrides :option:`-Wno-attribute-warning`.
4289
4290.. option:: -Wno-deprecated
4291
4292 Do not warn about usage of deprecated features. See :ref:`deprecated-features`.
4293
4294.. option:: -Wdeprecated
4295
4296 Default setting; overrides :option:`-Wno-deprecated`.
4297
4298.. option:: -Wno-deprecated-declarations
4299
4300 Do not warn about uses of functions (see :ref:`function-attributes`),
4301 variables (see :ref:`variable-attributes`), and types (see :ref:`type-attributes`) marked as deprecated by using the ``deprecated``
4302 attribute.
4303
4304.. option:: -Wdeprecated-declarations
4305
4306 Default setting; overrides :option:`-Wno-deprecated-declarations`.
4307
4308.. option:: -Wno-overflow
4309
4310 Do not warn about compile-time overflow in constant expressions.
4311
4312.. option:: -Woverflow
4313
4314 Default setting; overrides :option:`-Wno-overflow`.
4315
4316.. option:: -Wno-odr
4317
4318 Warn about One Definition Rule violations during link-time optimization.
4319 Enabled by default.
4320
4321.. option:: -Wodr
4322
4323 Default setting; overrides :option:`-Wno-odr`.
4324
4325.. index:: OpenACC accelerator programming
4326
4327.. option:: -Wopenacc-parallelism
4328
4329 Warn about potentially suboptimal choices related to OpenACC parallelism.
4330
4331.. option:: -Wno-openacc-parallelism
4332
4333 Default setting; overrides :option:`-Wopenacc-parallelism`.
4334
4335.. option:: -Wopenmp-simd
4336
4337 Warn if the vectorizer cost model overrides the OpenMP
4338 simd directive set by user. The :option:`-fsimd-cost-model=unlimited`
4339 option can be used to relax the cost model.
4340
4341.. option:: -Wno-openmp-simd
4342
4343 Default setting; overrides :option:`-Wopenmp-simd`.
4344
4345.. option:: -Woverride-init
4346
4347 .. note::
4348
4349 C and Objective-C only
4350
4351 Warn if an initialized field without side effects is overridden when
4352 using designated initializers (see :ref:`designated-inits`).
4353
4354 This warning is included in :option:`-Wextra`. To get other
4355 :option:`-Wextra` warnings without this one, use :option:`-Wextra
4356 -Wno-override-init`.
4357
4358.. option:: -Wno-override-init
4359
4360 Default setting; overrides :option:`-Woverride-init`.
4361
4362.. option:: -Wno-override-init-side-effects
4363
4364 .. note::
4365
4366 C and Objective-C only
4367
4368 Do not warn if an initialized field with side effects is overridden when
4369 using designated initializers (see :ref:`designated-inits`). This warning is enabled by default.
4370
4371.. option:: -Woverride-init-side-effects
4372
4373 Default setting; overrides :option:`-Wno-override-init-side-effects`.
4374
4375.. option:: -Wpacked
4376
4377 Warn if a structure is given the packed attribute, but the packed
4378 attribute has no effect on the layout or size of the structure.
4379 Such structures may be mis-aligned for little benefit. For
4380 instance, in this code, the variable ``f.x`` in ``struct bar``
4381 is misaligned even though ``struct bar`` does not itself
4382 have the packed attribute:
4383
4384 .. code-block:: c++
4385
4386 struct foo {
4387 int x;
4388 char a, b, c, d;
4389 } __attribute__((packed));
4390 struct bar {
4391 char z;
4392 struct foo f;
4393 };
4394
4395.. option:: -Wno-packed
4396
4397 Default setting; overrides :option:`-Wpacked`.
4398
4399.. option:: -Wnopacked-bitfield-compat
4400
4401 The 4.1, 4.2 and 4.3 series of GCC ignore the :var-attr:`packed` attribute
4402 on bit-fields of type ``char``. This was fixed in GCC 4.4 but
4403 the change can lead to differences in the structure layout. GCC
4404 informs you when the offset of such a field has changed in GCC 4.4.
4405 For example there is no longer a 4-bit padding between field ``a``
4406 and ``b`` in this structure:
4407
4408 .. code-block:: c++
4409
4410 struct foo
4411 {
4412 char a:4;
4413 char b:8;
4414 } __attribute__ ((packed));
4415
4416 This warning is enabled by default. Use
4417 :option:`-Wno-packed-bitfield-compat` to disable this warning.
4418
4419.. option:: -Wpacked-not-aligned
4420
4421 .. note::
4422
4423 C, C++, Objective-C and Objective-C++ only
4424
4425 Warn if a structure field with explicitly specified alignment in a
4426 packed struct or union is misaligned. For example, a warning will
4427 be issued on ``struct S``, like, ``warning: alignment 1 of
4428 'struct S' is less than 8``, in this code:
4429
4430 .. code-block:: c++
4431
4432 struct __attribute__ ((aligned (8))) S8 { char a[8]; };
4433 struct __attribute__ ((packed)) S {
4434 struct S8 s8;
4435 };
4436
4437 This warning is enabled by :option:`-Wall`.
4438
4439.. option:: -Wno-packed-not-aligned
4440
4441 Default setting; overrides :option:`-Wpacked-not-aligned`.
4442
4443.. option:: -Wpadded
4444
4445 Warn if padding is included in a structure, either to align an element
4446 of the structure or to align the whole structure. Sometimes when this
4447 happens it is possible to rearrange the fields of the structure to
4448 reduce the padding and so make the structure smaller.
4449
4450.. option:: -Wno-padded
4451
4452 Default setting; overrides :option:`-Wpadded`.
4453
4454.. option:: -Wredundant-decls
4455
4456 Warn if anything is declared more than once in the same scope, even in
4457 cases where multiple declaration is valid and changes nothing.
4458
4459.. option:: -Wno-redundant-decls
4460
4461 Default setting; overrides :option:`-Wredundant-decls`.
4462
4463.. option:: -Wrestrict
4464
4465 Warn when an object referenced by a ``restrict`` -qualified parameter
4466 (or, in C++, a ``__restrict`` -qualified parameter) is aliased by another
4467 argument, or when copies between such objects overlap. For example,
4468 the call to the ``strcpy`` function below attempts to truncate the string
4469 by replacing its initial characters with the last four. However, because
4470 the call writes the terminating NUL into ``a[4]``, the copies overlap and
4471 the call is diagnosed.
4472
4473 .. code-block:: c++
4474
4475 void foo (void)
4476 {
4477 char a[] = "abcd1234";
4478 strcpy (a, a + 4);
4479 ...
4480 }
4481
4482 The :option:`-Wrestrict` option detects some instances of simple overlap
4483 even without optimization but works best at :option:`-O2` and above. It
4484 is included in :option:`-Wall`.
4485
4486.. option:: -Wno-restrict
4487
4488 Default setting; overrides :option:`-Wrestrict`.
4489
4490.. option:: -Wnested-externs
4491
4492 .. note::
4493
4494 C and Objective-C only
4495
4496 Warn if an ``extern`` declaration is encountered within a function.
4497
4498.. option:: -Wno-nested-externs
4499
4500 Default setting; overrides :option:`-Wnested-externs`.
4501
4502.. option:: -Winline
4503
4504 Warn if a function that is declared as inline cannot be inlined.
4505 Even with this option, the compiler does not warn about failures to
4506 inline functions declared in system headers.
4507
4508 The compiler uses a variety of heuristics to determine whether or not
4509 to inline a function. For example, the compiler takes into account
4510 the size of the function being inlined and the amount of inlining
4511 that has already been done in the current function. Therefore,
4512 seemingly insignificant changes in the source program can cause the
4513 warnings produced by :option:`-Winline` to appear or disappear.
4514
4515.. option:: -Wno-inline
4516
4517 Default setting; overrides :option:`-Winline`.
4518
4519.. option:: -Winterference-size
4520
4521 Warn about use of C++17 ``std::hardware_destructive_interference_size``
4522 without specifying its value with :option:`--param destructive-interference-size`.
4523 Also warn about questionable values for that option.
4524
4525 This variable is intended to be used for controlling class layout, to
4526 avoid false sharing in concurrent code:
4527
4528 .. code-block:: c++
4529
4530 struct independent_fields {
4531 alignas(std::hardware_destructive_interference_size) std::atomic<int> one;
4532 alignas(std::hardware_destructive_interference_size) std::atomic<int> two;
4533 };
4534
4535 Here :samp:`one` and :samp:`two` are intended to be far enough apart
4536 that stores to one won't require accesses to the other to reload the
4537 cache line.
4538
4539 By default, :option:`--param destructive-interference-size` and
4540 :option:`--param constructive-interference-size` are set based on the
4541 current :option:`-mtune` option, typically to the L1 cache line size
4542 for the particular target CPU, sometimes to a range if tuning for a
4543 generic target. So all translation units that depend on ABI
4544 compatibility for the use of these variables must be compiled with
4545 the same :option:`-mtune` (or :option:`-mcpu`).
4546
4547 If ABI stability is important, such as if the use is in a header for a
4548 library, you should probably not use the hardware interference size
4549 variables at all. Alternatively, you can force a particular value
4550 with :option:`--param`.
4551
4552 If you are confident that your use of the variable does not affect ABI
4553 outside a single build of your project, you can turn off the warning
4554 with :option:`-Wno-interference-size`.
4555
4556.. option:: -Wint-in-bool-context
4557
4558 Warn for suspicious use of integer values where boolean values are expected,
4559 such as conditional expressions (?:) using non-boolean integer constants in
4560 boolean context, like ``if (a <= b ? 2 : 3)``. Or left shifting of signed
4561 integers in boolean context, like ``for (a = 0; 1 << a; a++);``. Likewise
4562 for all kinds of multiplications regardless of the data type.
4563 This warning is enabled by :option:`-Wall`.
4564
4565.. option:: -Wno-int-in-bool-context
4566
4567 Default setting; overrides :option:`-Wint-in-bool-context`.
4568
4569.. option:: -Wno-int-to-pointer-cast
4570
4571 Suppress warnings from casts to pointer type of an integer of a
4572 different size. In C++, casting to a pointer type of smaller size is
4573 an error. Wint-to-pointer-cast is enabled by default.
4574
4575.. option:: -Wint-to-pointer-cast
4576
4577 Default setting; overrides :option:`-Wno-int-to-pointer-cast`.
4578
4579.. option:: -Wno-pointer-to-int-cast
4580
4581 .. note::
4582
4583 C and Objective-C only
4584
4585 Suppress warnings from casts from a pointer to an integer type of a
4586 different size.
4587
4588.. option:: -Wpointer-to-int-cast
4589
4590 Default setting; overrides :option:`-Wno-pointer-to-int-cast`.
4591
4592.. option:: -Winvalid-pch
4593
4594 Warn if a precompiled header (see :ref:`precompiled-headers`) is found in
4595 the search path but cannot be used.
4596
4597.. option:: -Wno-invalid-pch
4598
4599 Default setting; overrides :option:`-Winvalid-pch`.
4600
4601.. option:: -Winvalid-utf8
4602
4603 Warn if an invalid UTF-8 character is found.
4604 This warning is on by default for C++23 if :option:`-finput-charset=UTF-8`
4605 is used and turned into error with :option:`-pedantic-errors`.
4606
4607.. option:: -Wno-invalid-utf8
4608
4609 Default setting; overrides :option:`-Winvalid-utf8`.
4610
4611.. option:: -Wno-unicode
4612
4613 Don't diagnose invalid forms of delimited or named escape sequences which are
4614 treated as separate tokens. Wunicode is enabled by default.
4615
4616.. option:: -Wunicode
4617
4618 Default setting; overrides :option:`-Wno-unicode`.
4619
4620.. option:: -Wlong-long
4621
4622 Warn if ``long long`` type is used. This is enabled by either
4623 :option:`-Wpedantic` or :option:`-Wtraditional` in ISO C90 and C++98
4624 modes. To inhibit the warning messages, use :option:`-Wno-long-long`.
4625
4626.. option:: -Wno-long-long
4627
4628 Default setting; overrides :option:`-Wlong-long`.
4629
4630.. option:: -Wvariadic-macros
4631
4632 Warn if variadic macros are used in ISO C90 mode, or if the GNU
4633 alternate syntax is used in ISO C99 mode. This is enabled by either
4634 :option:`-Wpedantic` or :option:`-Wtraditional`. To inhibit the warning
4635 messages, use :option:`-Wno-variadic-macros`.
4636
4637.. option:: -Wno-variadic-macros
4638
4639 Default setting; overrides :option:`-Wvariadic-macros`.
4640
4641.. option:: -Wno-varargs
4642
4643 Do not warn upon questionable usage of the macros used to handle variable
4644 arguments like ``va_start``. These warnings are enabled by default.
4645
4646.. option:: -Wvarargs
4647
4648 Default setting; overrides :option:`-Wno-varargs`.
4649
4650.. option:: -Wvector-operation-performance
4651
4652 Warn if vector operation is not implemented via SIMD capabilities of the
4653 architecture. Mainly useful for the performance tuning.
4654 Vector operation can be implemented ``piecewise``, which means that the
4655 scalar operation is performed on every vector element;
4656 ``in parallel``, which means that the vector operation is implemented
4657 using scalars of wider type, which normally is more performance efficient;
4658 and ``as a single scalar``, which means that vector fits into a
4659 scalar type.
4660
4661.. option:: -Wno-vector-operation-performance
4662
4663 Default setting; overrides :option:`-Wvector-operation-performance`.
4664
4665.. option:: -Wvla
4666
4667 Warn if a variable-length array is used in the code.
4668 :option:`-Wno-vla` prevents the :option:`-Wpedantic` warning of
4669 the variable-length array.
4670
4671.. option:: -Wno-vla
4672
4673 Default setting; overrides :option:`-Wvla`.
4674
4675.. option:: -Wvla-larger-than={byte-size}
4676
4677 If this option is used, the compiler warns for declarations of
4678 variable-length arrays whose size is either unbounded, or bounded
4679 by an argument that allows the array size to exceed :samp:`{byte-size}`
4680 bytes. This is similar to how :option:`-Walloca-larger-than=byte-size`
4681 works, but with variable-length arrays.
4682
4683 Note that GCC may optimize small variable-length arrays of a known
4684 value into plain arrays, so this warning may not get triggered for
4685 such arrays.
4686
4687 :option:`-Wvla-larger-than=PTRDIFF_MAX` is enabled by default but
4688 is typically only effective when :option:`-ftree-vrp` is active (default
4689 for :option:`-O2` and above).
4690
4691 See also :option:`-Walloca-larger-than=byte-size`.
4692
4693.. option:: -Wno-vla-larger-than
4694
4695 Disable :option:`-Wvla-larger-than=` warnings. The option is equivalent
4696 to :option:`-Wvla-larger-than=SIZE_MAX` or larger.
4697
4698.. option:: -Wvla-parameter
4699
4700 Warn about redeclarations of functions involving arguments of Variable
4701 Length Array types of inconsistent kinds or forms, and enable the detection
4702 of out-of-bounds accesses to such parameters by warnings such as
4703 :option:`-Warray-bounds`.
4704
4705 If the first function declaration uses the VLA form the bound specified
4706 in the array is assumed to be the minimum number of elements expected to
4707 be provided in calls to the function and the maximum number of elements
4708 accessed by it. Failing to provide arguments of sufficient size or
4709 accessing more than the maximum number of elements may be diagnosed.
4710
4711 For example, the warning triggers for the following redeclarations because
4712 the first one allows an array of any size to be passed to ``f`` while
4713 the second one specifies that the array argument must have at least ``n``
4714 elements. In addition, calling ``f`` with the associated VLA bound
4715 parameter in excess of the actual VLA bound triggers a warning as well.
4716
4717 .. code-block:: c++
4718
4719 void f (int n, int[n]);
4720 void f (int, int[]); // warning: argument 2 previously declared as a VLA
4721
4722 void g (int n)
4723 {
4724 if (n > 4)
4725 return;
4726 int a[n];
4727 f (sizeof a, a); // warning: access to a by f may be out of bounds
4728 ...
4729 }
4730
4731 :option:`-Wvla-parameter` is included in :option:`-Wall`. The
4732 :option:`-Warray-parameter` option triggers warnings for similar problems
4733 involving ordinary array arguments.
4734
4735.. option:: -Wno-vla-parameter
4736
4737 Default setting; overrides :option:`-Wvla-parameter`.
4738
4739.. option:: -Wvolatile-register-var
4740
4741 Warn if a register variable is declared volatile. The volatile
4742 modifier does not inhibit all optimizations that may eliminate reads
4743 and/or writes to register variables. This warning is enabled by
4744 :option:`-Wall`.
4745
4746.. option:: -Wno-volatile-register-var
4747
4748 Default setting; overrides :option:`-Wvolatile-register-var`.
4749
4750.. option:: -Wxor-used-as-pow
4751
4752 .. note::
4753
4754 C, C++, Objective-C and Objective-C++ only
4755
4756 Warn about uses of ``^``, the exclusive or operator, where it appears
4757 the user meant exponentiation. Specifically, the warning occurs when the
4758 left-hand side is the decimal constant 2 or 10 and the right-hand side
4759 is also a decimal constant.
4760
4761 In C and C++, ``^`` means exclusive or, whereas in some other languages
4762 (e.g. TeX and some versions of BASIC) it means exponentiation.
4763
4764 This warning is enabled by default. It can be silenced by converting one
4765 of the operands to hexadecimal.
4766
4767.. option:: -Wno-xor-used-as-pow
4768
4769 Default setting; overrides :option:`-Wxor-used-as-pow`.
4770
4771.. option:: -Wdisabled-optimization
4772
4773 Warn if a requested optimization pass is disabled. This warning does
4774 not generally indicate that there is anything wrong with your code; it
4775 merely indicates that GCC's optimizers are unable to handle the code
4776 effectively. Often, the problem is that your code is too big or too
4777 complex; GCC refuses to optimize programs when the optimization
4778 itself is likely to take inordinate amounts of time.
4779
4780.. option:: -Wno-disabled-optimization
4781
4782 Default setting; overrides :option:`-Wdisabled-optimization`.
4783
4784.. option:: -Wpointer-sign
4785
4786 .. note::
4787
4788 C and Objective-C only
4789
4790 Warn for pointer argument passing or assignment with different signedness.
4791 This option is only supported for C and Objective-C. It is implied by
4792 :option:`-Wall` and by :option:`-Wpedantic`, which can be disabled with
4793 :option:`-Wno-pointer-sign`.
4794
4795.. option:: -Wno-pointer-sign
4796
4797 Default setting; overrides :option:`-Wpointer-sign`.
4798
4799.. option:: -Wstack-protector
4800
4801 This option is only active when :option:`-fstack-protector` is active. It
4802 warns about functions that are not protected against stack smashing.
4803
4804.. option:: -Wno-stack-protector
4805
4806 Default setting; overrides :option:`-Wstack-protector`.
4807
4808.. option:: -Woverlength-strings
4809
4810 Warn about string constants that are longer than the 'minimum
4811 maximum' length specified in the C standard. Modern compilers
4812 generally allow string constants that are much longer than the
4813 standard's minimum limit, but very portable programs should avoid
4814 using longer strings.
4815
4816 The limit applies *after* string constant concatenation, and does
4817 not count the trailing NUL. In C90, the limit was 509 characters; in
4818 C99, it was raised to 4095. C++98 does not specify a normative
4819 minimum maximum, so we do not diagnose overlength strings in C++.
4820
4821 This option is implied by :option:`-Wpedantic`, and can be disabled with
4822 :option:`-Wno-overlength-strings`.
4823
4824.. option:: -Wno-overlength-strings
4825
4826 Default setting; overrides :option:`-Woverlength-strings`.
4827
4828.. option:: -Wunsuffixed-float-constants
4829
4830 .. note::
4831
4832 C and Objective-C only
4833
4834 Issue a warning for any floating constant that does not have
4835 a suffix. When used together with :option:`-Wsystem-headers` it
4836 warns about such constants in system header files. This can be useful
4837 when preparing code to use with the ``FLOAT_CONST_DECIMAL64`` pragma
4838 from the decimal floating-point extension to C99.
4839
4840.. option:: -Wno-unsuffixed-float-constants
4841
4842 Default setting; overrides :option:`-Wunsuffixed-float-constants`.
4843
4844.. option:: -Wno-lto-type-mismatch
4845
4846 During the link-time optimization, do not warn about type mismatches in
4847 global declarations from different compilation units.
4848 Requires :option:`-flto` to be enabled. Enabled by default.
4849
4850.. option:: -Wlto-type-mismatch
4851
4852 Default setting; overrides :option:`-Wno-lto-type-mismatch`.
4853
4854.. option:: -Wno-designated-init
4855
4856 .. note::
4857
4858 C and Objective-C only
4859
4860 Suppress warnings when a positional initializer is used to initialize
4861 a structure that has been marked with the :type-attr:`designated_init`
4862 attribute.
4863
4864.. option:: -Wdesignated-init
4865
3ed1b4ce 4866 Default setting; overrides :option:`-Wno-designated-init`.