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.
6 .. index:: options to control warnings, warning messages, messages, warning, suppressing warnings
10 Options to Request or Suppress Warnings
11 ***************************************
13 Warnings are diagnostic messages that report constructions that
14 are not inherently erroneous but that are risky or suggest there
15 may have been an error.
17 The following language-independent options do not enable specific
18 warnings but control the kinds of diagnostics produced by GCC.
20 .. index:: syntax checking
22 .. option:: -fsyntax-only
24 Check the code for syntax errors, but don't do anything beyond that.
26 .. option:: -fmax-errors={n}
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
37 Inhibit all warning messages.
41 Make all warnings into errors.
43 .. option:: -Wno-error
45 Default setting; overrides :option:`-Werror`.
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`
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.)
63 Note that specifying :option:`-Werror=foo` automatically implies
64 :option:`-Wfoo`. However, :option:`-Wno-error=foo` does not
67 .. option:: -Wno-error=
69 Default setting; overrides :option:`-Werror=`.
71 .. option:: -Wfatal-errors
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
77 .. option:: -Wno-fatal-errors
79 Default setting; overrides :option:`-Wfatal-errors`.
81 You can request many specific warnings with options beginning with
82 :samp:`-W`, for example :option:`-Wimplicit` to request warnings on
83 implicit declarations. Each of these specific warning options also
84 has a negative form beginning :samp:`-Wno-` to turn off warnings; for
85 example, :option:`-Wno-implicit`. This manual lists only one of the
86 two forms, whichever is not the default. For further
87 language-specific options also refer to :ref:`c++-dialect-options` and
88 :ref:`objective-c-and-objective-c++-dialect-options`.
89 Additional warnings can be produced by enabling the static analyzer;
90 See :ref:`static-analyzer-options`.
92 Some options, such as :option:`-Wall` and :option:`-Wextra`, turn on other
93 options, such as :option:`-Wunused`, which may turn on further options,
94 such as :option:`-Wunused-value`. The combined effect of positive and
95 negative forms is that more specific options have priority over less
96 specific ones, independently of their position in the command-line. For
97 options of the same specificity, the last one takes effect. Options
98 enabled or disabled via pragmas (see :ref:`diagnostic-pragmas`) take effect
99 as if they appeared at the end of the command-line.
101 When an unrecognized warning option is requested (e.g.,
102 :option:`-Wunknown-warning`), GCC emits a diagnostic stating
103 that the option is not recognized. However, if the :option:`-Wno-` form
104 is used, the behavior is slightly different: no diagnostic is
105 produced for :option:`-Wno-unknown-warning` unless other diagnostics
106 are being produced. This allows the use of new :option:`-Wno-` options
107 with old compilers, but if something goes wrong, the compiler
108 warns that an unrecognized option is present.
110 The effectiveness of some warnings depends on optimizations also being
111 enabled. For example :option:`-Wsuggest-final-types` is more effective
112 with link-time optimization and some instances of other warnings may
113 not be issued at all unless optimization is enabled. While optimization
114 in general improves the efficacy of control and data flow sensitive
115 warnings, in some cases it may also cause false positives.
117 .. option:: -Wpedantic, -pedantic
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.
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.
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`.
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.
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.
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.)
160 .. option:: -Wno-pedantic
162 Default setting; overrides :option:`-Wpedantic`.
164 .. option:: -pedantic-errors
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.
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`.
180 :option:`-Wall` turns on the following warning flags:
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`
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.
258 Default setting; overrides :option:`-Wall`.
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.)
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
288 * A pointer is compared against integer zero with ``<``, ``<=``,
291 * (C++ only) An enumerator and a non-enumerator both appear in a
292 conditional expression.
294 * (C++ only) Ambiguous virtual bases.
296 * (C++ only) Subscripting an array that has been declared ``register``.
298 * (C++ only) Taking the address of a variable that has been declared
301 * (C++ only) A base class is not initialized in the copy constructor
304 .. option:: -Wno-extra
306 Default setting; overrides :option:`-Wextra`.
312 C, Objective-C, C++ and Objective-C++ only
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.
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`).
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`.
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.
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
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.
347 Known incompatibilities in :option:`-fabi-version=2` (which was the
348 default from GCC 3.4 to 4.9) include:
350 * A template with a non-type template parameter of reference type was
356 template <int &> struct S {};
359 This was fixed in :option:`-fabi-version=3`.
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.
365 The mangling was changed in :option:`-fabi-version=4`.
367 * ``__attribute ((const))`` and :fn-attr:`noreturn` were mangled as type
368 qualifiers, and ``decltype`` of a plain declaration was folded away.
370 These mangling issues were fixed in :option:`-fabi-version=5`.
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``.
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.
381 These issues were corrected in :option:`-fabi-version=6`.
383 * Lambdas in default argument scope were mangled incorrectly, and the
384 ABI changed the mangling of ``nullptr_t``.
386 These issues were corrected in :option:`-fabi-version=7`.
388 * When mangling a function type with function-cv-qualifiers, the
389 un-qualified function type was incorrectly treated as a substitution
392 This was fixed in :option:`-fabi-version=8`, the default for GCC 5.1.
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
399 This was fixed in :option:`-fabi-version=9`, the default for GCC 5.2.
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.
406 This was fixed in :option:`-fabi-version=10`, the default for GCC 6.1.
408 This option also enables warnings about psABI-related changes.
409 The known psABI changes at this point include:
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:
422 ``union U`` is now always passed in memory.
426 Default setting; overrides :option:`-Wabi`.
428 .. option:: -Wchar-subscripts
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
433 This warning is enabled by :option:`-Wall`.
435 .. option:: -Wno-char-subscripts
437 Default setting; overrides :option:`-Wchar-subscripts`.
439 .. option:: -Wno-coverage-mismatch
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.
454 .. option:: -Wcoverage-mismatch
456 Default setting; overrides :option:`-Wno-coverage-mismatch`.
458 .. option:: -Wno-coverage-invalid-line-number
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.
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
469 .. option:: -Wcoverage-invalid-line-number
471 Default setting; overrides :option:`-Wno-coverage-invalid-line-number`.
477 C, Objective-C, C++, Objective-C++ and Fortran only
479 Suppress warning messages emitted by ``#warning`` directives.
483 Default setting; overrides :option:`-Wno-cpp`.
485 .. option:: -Wdouble-promotion
489 C, C++, Objective-C and Objective-C++ only
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.
498 It is easy to accidentally do computations with ``double`` because
499 floating-point literals are implicitly of type ``double``. For
504 float area(float radius)
506 return 3.14159 * radius * radius;
509 the compiler performs the entire computation with ``double``
510 because the floating-point literal is a ``double``.
512 .. option:: -Wno-double-promotion
514 Default setting; overrides :option:`-Wdouble-promotion`.
516 .. option:: -Wduplicate-decl-specifier
520 C and Objective-C only
522 Warn if a declaration has duplicate ``const``, ``volatile``,
523 ``restrict`` or ``_Atomic`` specifier. This warning is enabled by
526 .. option:: -Wno-duplicate-decl-specifier
528 Default setting; overrides :option:`-Wduplicate-decl-specifier`.
530 .. option:: -Wformat, -Wformat={n}
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`.
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`.
554 .. option:: -Wformat=1
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`.
565 .. option:: -Wformat=2
567 Enable :option:`-Wformat` plus additional format checks. Currently
568 equivalent to :option:`-Wformat` :option:`-Wformat-nonliteral` :option:`-Wformat-security`
569 :option:`-Wformat-y2k`.
571 .. option:: -Wno-format
573 Default setting; overrides :option:`-Wformat`.
575 .. option:: -Wno-format-contains-nul
577 If :option:`-Wformat` is specified, do not warn about format strings that
580 .. option:: -Wformat-contains-nul
582 Default setting; overrides :option:`-Wno-format-contains-nul`.
584 .. option:: -Wno-format-extra-args
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.
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.
598 .. option:: -Wformat-extra-args
600 Default setting; overrides :option:`-Wno-format-extra-args`.
602 .. option:: -Wformat-overflow, -Wformat-overflow={level}
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.
612 .. option:: -Wformat-overflow, -Wformat-overflow=1
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.
631 void f (int a, int b)
634 sprintf (buf, "a = %i, b = %i\n", a, b);
637 .. option:: -Wno-format-overflow
639 Default setting; overrides :option:`-Wformat-overflow`.
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.
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.
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.
673 void f (int a, int b)
676 sprintf (buf, "a = %hi, b = %i\n", a, (short)b);
679 .. option:: -Wno-format-overflow
681 Default setting; overrides :option:`-Wformat-overflow`.
683 .. option:: -Wno-format-zero-length
685 If :option:`-Wformat` is specified, do not warn about zero-length formats.
686 The C standard specifies that zero-length formats are allowed.
688 .. option:: -Wformat-zero-length
690 Default setting; overrides :option:`-Wno-format-zero-length`.
692 .. option:: -Wformat-nonliteral
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``.
698 .. option:: -Wno-format-nonliteral
700 Default setting; overrides :option:`-Wformat-nonliteral`.
702 .. option:: -Wformat-security
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`.)
714 .. option:: -Wno-format-security
716 Default setting; overrides :option:`-Wformat-security`.
718 .. option:: -Wformat-signedness
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.
723 .. option:: -Wno-format-signedness
725 Default setting; overrides :option:`-Wformat-signedness`.
727 .. option:: -Wformat-truncation, -Wformat-truncation={level}
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`.
738 .. option:: -Wformat-truncation, -Wformat-truncation=1
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.
745 .. option:: -Wformat-truncation=2
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.
751 .. option:: -Wno-format-truncation
753 Default setting; overrides :option:`-Wformat-truncation`.
755 .. option:: -Wformat-y2k
757 If :option:`-Wformat` is specified, also warn about ``strftime``
758 formats that may yield only a two-digit year.
760 .. option:: -Wno-format-y2k
762 Default setting; overrides :option:`-Wformat-y2k`.
764 .. option:: -Wnonnull
766 Warn about passing a null pointer for arguments marked as
767 requiring a non-null value by the :fn-attr:`nonnull` function attribute.
769 :option:`-Wnonnull` is included in :option:`-Wall` and :option:`-Wformat`. It
770 can be disabled with the :option:`-Wno-nonnull` option.
772 .. option:: -Wno-nonnull
774 Default setting; overrides :option:`-Wnonnull`.
776 .. option:: -Wnonnull-compare
778 Warn when comparing an argument marked with the :fn-attr:`nonnull`
779 function attribute against null inside the function.
781 :option:`-Wnonnull-compare` is included in :option:`-Wall`. It
782 can be disabled with the :option:`-Wno-nonnull-compare` option.
784 .. option:: -Wno-nonnull-compare
786 Default setting; overrides :option:`-Wnonnull-compare`.
788 .. option:: -Wnull-dereference
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.
796 .. option:: -Wno-null-dereference
798 Default setting; overrides :option:`-Wnull-dereference`.
800 .. option:: -Winfinite-recursion
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`.
807 .. option:: -Wno-infinite-recursion
809 Default setting; overrides :option:`-Winfinite-recursion`.
811 .. option:: -Winit-self
815 C, C++, Objective-C and Objective-C++ only
817 Warn about uninitialized variables that are initialized with themselves.
818 Note this option can only be used with the :option:`-Wuninitialized` option.
820 For example, GCC warns about ``i`` being uninitialized in the
821 following snippet only when :option:`-Winit-self` has been specified:
831 This warning is enabled by :option:`-Wall` in C++.
833 .. option:: -Wno-init-self
835 Default setting; overrides :option:`-Winit-self`.
837 .. option:: -Wno-implicit-int
841 C and Objective-C only
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`.
847 .. option:: -Wimplicit-int
849 Default setting; overrides :option:`-Wno-implicit-int`.
851 .. option:: -Wno-implicit-function-declaration
855 C and Objective-C only
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`.
862 .. option:: -Wimplicit-function-declaration
864 Default setting; overrides :option:`-Wno-implicit-function-declaration`.
866 .. option:: -Wimplicit
870 C and Objective-C only
872 Same as :option:`-Wimplicit-int` and :option:`-Wimplicit-function-declaration`.
873 This warning is enabled by :option:`-Wall`.
875 .. option:: -Wno-implicit
877 Default setting; overrides :option:`-Wimplicit`.
879 .. option:: -Wimplicit-fallthrough
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`.
885 .. option:: -Wno-implicit-fallthrough
887 Default setting; overrides :option:`-Wimplicit-fallthrough`.
889 .. option:: -Wimplicit-fallthrough={n}
891 Warn when a switch case falls through. For example:
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.
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:
940 __attribute__ ((fallthrough));
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:
953 * :option:`-Wimplicit-fallthrough=0` disables the warning altogether.
955 * :option:`-Wimplicit-fallthrough=1` matches ``.*`` regular
956 expression, any comment is used as fallthrough comment.
958 * :option:`-Wimplicit-fallthrough=2` case insensitively matches
959 ``.*falls?[ \t-]*thr(ough|u).*`` regular expression.
961 * :option:`-Wimplicit-fallthrough=3` case sensitively matches one of the
962 following regular expressions:
968 * ``lint -fallthrough[ \t]*``
970 * ``[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
971 FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?``
973 * ``[ \t.!]*(Else,? |Intentional(ly)? )?
974 Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?``
976 * ``[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
977 fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?``
979 * :option:`-Wimplicit-fallthrough=4` case sensitively matches one of the
980 following regular expressions:
986 * ``lint -fallthrough[ \t]*``
988 * ``[ \t]*FALLTHR(OUGH|U)[ \t]*``
990 * :option:`-Wimplicit-fallthrough=5` doesn't recognize any comments as
991 fallthrough comments, only attributes disable the warning.
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.
1008 The :option:`-Wimplicit-fallthrough=3` warning is enabled by :option:`-Wextra`.
1010 .. option:: -Wno-if-not-aligned
1014 C, C++, Objective-C and Objective-C++ only
1016 Control if warnings triggered by the ``warn_if_not_aligned`` attribute
1017 should be issued. These warnings are enabled by default.
1019 .. option:: -Wif-not-aligned
1021 Default setting; overrides :option:`-Wno-if-not-aligned`.
1023 .. option:: -Wignored-qualifiers
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.
1037 This warning is also enabled by :option:`-Wextra`.
1039 .. option:: -Wno-ignored-qualifiers
1041 Default setting; overrides :option:`-Wignored-qualifiers`.
1043 .. option:: -Wno-ignored-attributes
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.
1055 .. option:: -Wignored-attributes
1057 Default setting; overrides :option:`-Wno-ignored-attributes`.
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`.
1067 .. option:: -Wno-main
1069 Default setting; overrides :option:`-Wmain`.
1071 .. option:: -Wmisleading-indentation
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.
1082 In the following example, the call to 'bar' is misleadingly indented as
1083 if it were guarded by the 'if' conditional.
1087 if (some_condition ())
1089 bar (); /* Gotcha: this is not guarded by the "if". */
1091 In the case of mixed tabs and spaces, the warning uses the
1092 :option:`-ftabstop=` option to determine if the statements line up
1095 The warning is not issued for code involving multiline preprocessor logic
1096 such as the following example.
1102 #if SOME_CONDITION_THAT_DOES_NOT_HOLD
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.
1111 This warning is enabled by :option:`-Wall` in C and C++.
1113 .. option:: -Wno-misleading-indentation
1115 Default setting; overrides :option:`-Wmisleading-indentation`.
1117 .. option:: -Wmissing-attributes
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`.
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`).
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`).
1147 :option:`-Wmissing-attributes` is enabled by :option:`-Wall`.
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.
1157 T* __attribute__ ((malloc, alloc_size (1)))
1161 void* __attribute__ ((malloc)) // missing alloc_size
1162 allocate<void> (size_t);
1164 .. option:: -Wno-missing-attributes
1166 Default setting; overrides :option:`-Wmissing-attributes`.
1168 .. option:: -Wmissing-braces
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.
1176 int a[2][2] = { 0, 1, 2, 3 };
1177 int b[2][2] = { { 0, 1 }, { 2, 3 } };
1179 This warning is enabled by :option:`-Wall`.
1181 .. option:: -Wno-missing-braces
1183 Default setting; overrides :option:`-Wmissing-braces`.
1185 .. option:: -Wmissing-include-dirs
1189 C, C++, Objective-C, Objective-C++ and Fortran only
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.
1195 .. option:: -Wno-missing-include-dirs
1197 Default setting; overrides :option:`-Wmissing-include-dirs`.
1199 .. option:: -Wno-missing-profile
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.
1217 .. option:: -Wmissing-profile
1219 Default setting; overrides :option:`-Wno-missing-profile`.
1221 .. option:: -Wmismatched-dealloc
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
1236 void mydealloc (void*);
1238 __attribute__ ((malloc (mydealloc, 1))) void*
1243 void *p = myalloc (32);
1245 free (p); // warning: not a matching deallocator for myalloc
1246 mydealloc (p); // ok
1249 In C++, the related option :option:`-Wmismatched-new-delete` diagnoses
1250 mismatches involving either ``operator new`` or ``operator delete``.
1252 Option :option:`-Wmismatched-dealloc` is included in :option:`-Wall`.
1254 .. option:: -Wno-mismatched-dealloc
1256 Default setting; overrides :option:`-Wmismatched-dealloc`.
1258 .. option:: -Wmultistatement-macros
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.
1269 #define DOIT x++; y++
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:
1278 #define DOIT do { x++; y++; } while (0)
1282 This warning is enabled by :option:`-Wall` in C and C++.
1284 .. option:: -Wno-multistatement-macros
1286 Default setting; overrides :option:`-Wmultistatement-macros`.
1288 .. option:: -Wparentheses
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.
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.
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.
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
1312 // Declares a local variable called mymutex.
1313 std::unique_lock<std::mutex> (mymutex);
1314 // User meant std::unique_lock<std::mutex> lock (mymutex);
1317 This warning is enabled by :option:`-Wall`.
1319 .. option:: -Wno-parentheses
1321 Default setting; overrides :option:`-Wparentheses`.
1323 .. option:: -Wno-self-move
1327 C++ and Objective-C++ only
1329 This warning warns when a value is moved to itself with ``std::move``.
1330 Such a ``std::move`` typically has no effect.
1344 This warning is enabled by :option:`-Wall`.
1346 .. option:: -Wself-move
1348 Default setting; overrides :option:`-Wno-self-move`.
1350 .. option:: -Wsequence-point
1352 Warn about code that may have undefined semantics because of violations
1353 of sequence point rules in the C and C++ standards.
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.
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.
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.
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++.
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.
1400 This warning is enabled by :option:`-Wall` for C and C++.
1402 .. option:: -Wno-sequence-point
1404 Default setting; overrides :option:`-Wsequence-point`.
1406 .. option:: -Wno-return-local-addr
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.
1411 .. option:: -Wreturn-local-addr
1413 Default setting; overrides :option:`-Wno-return-local-addr`.
1415 .. option:: -Wreturn-type
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
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.
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.
1435 This warning is enabled by default in C++ and by :option:`-Wall` otherwise.
1437 .. option:: -Wno-return-type
1439 Default setting; overrides :option:`-Wreturn-type`.
1441 .. option:: -Wno-shift-count-negative
1443 Controls warnings if a shift count is negative.
1444 This warning is enabled by default.
1446 .. option:: -Wshift-count-negative
1448 Default setting; overrides :option:`-Wno-shift-count-negative`.
1450 .. option:: -Wno-shift-count-overflow
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.
1455 .. option:: -Wshift-count-overflow
1457 Default setting; overrides :option:`-Wno-shift-count-overflow`.
1459 .. option:: -Wshift-negative-value
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.
1464 .. option:: -Wno-shift-negative-value
1466 Default setting; overrides :option:`-Wshift-negative-value`.
1468 .. option:: -Wno-shift-overflow, -Wshift-overflow={n}
1470 These options control warnings about left shift overflows.
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
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.
1484 .. option:: -Wshift-overflow
1486 Default setting; overrides :option:`-Wno-shift-overflow`.
1488 .. option:: -Wswitch
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
1496 This warning is enabled by :option:`-Wall`.
1498 .. option:: -Wno-switch
1500 Default setting; overrides :option:`-Wswitch`.
1502 .. option:: -Wswitch-default
1504 Warn whenever a ``switch`` statement does not have a ``default``
1507 .. option:: -Wno-switch-default
1509 Default setting; overrides :option:`-Wswitch-default`.
1511 .. option:: -Wswitch-enum
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
1521 .. option:: -Wno-switch-enum
1523 Default setting; overrides :option:`-Wswitch-enum`.
1525 .. option:: -Wno-switch-bool
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:
1534 switch ((int) (a == 4))
1539 This warning is enabled by default for C and C++ programs.
1541 .. option:: -Wswitch-bool
1543 Default setting; overrides :option:`-Wno-switch-bool`.
1545 .. option:: -Wno-switch-outside-range
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
1552 .. option:: -Wswitch-outside-range
1554 Default setting; overrides :option:`-Wno-switch-outside-range`.
1556 .. option:: -Wno-switch-unreachable
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:
1572 :option:`-Wswitch-unreachable` does not warn if the statement between the
1573 controlling expression and the first case label is just a declaration:
1586 This warning is enabled by default for C and C++ programs.
1588 .. option:: -Wswitch-unreachable
1590 Default setting; overrides :option:`-Wno-switch-unreachable`.
1592 .. option:: -Wsync-nand
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.
1601 .. option:: -Wno-sync-nand
1603 Default setting; overrides :option:`-Wsync-nand`.
1605 .. option:: -Wtrivial-auto-var-init
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``
1612 .. option:: -Wno-trivial-auto-var-init
1614 Default setting; overrides :option:`-Wtrivial-auto-var-init`.
1616 .. option:: -Wunused-but-set-parameter
1618 Warn whenever a function parameter is assigned to, but otherwise unused
1619 (aside from its declaration).
1621 To suppress this warning use the :var-attr:`unused` attribute
1622 (see :ref:`variable-attributes`).
1624 This warning is also enabled by :option:`-Wunused` together with
1627 .. option:: -Wno-unused-but-set-parameter
1629 Default setting; overrides :option:`-Wunused-but-set-parameter`.
1631 .. option:: -Wunused-but-set-variable
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`.
1637 To suppress this warning use the :var-attr:`unused` attribute
1638 (see :ref:`variable-attributes`).
1640 This warning is also enabled by :option:`-Wunused`, which is enabled
1643 .. option:: -Wno-unused-but-set-variable
1645 Default setting; overrides :option:`-Wunused-but-set-variable`.
1647 .. option:: -Wunused-function
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`.
1653 .. option:: -Wno-unused-function
1655 Default setting; overrides :option:`-Wunused-function`.
1657 .. option:: -Wunused-label
1659 Warn whenever a label is declared but not used.
1660 This warning is enabled by :option:`-Wall`.
1662 To suppress this warning use the :var-attr:`unused` attribute
1663 (see :ref:`variable-attributes`).
1665 .. option:: -Wno-unused-label
1667 Default setting; overrides :option:`-Wunused-label`.
1669 .. option:: -Wunused-local-typedefs
1673 C, Objective-C, C++ and Objective-C++ only
1675 Warn when a typedef locally defined in a function is not used.
1676 This warning is enabled by :option:`-Wall`.
1678 .. option:: -Wno-unused-local-typedefs
1680 Default setting; overrides :option:`-Wunused-local-typedefs`.
1682 .. option:: -Wunused-parameter
1684 Warn whenever a function parameter is unused aside from its declaration.
1686 To suppress this warning use the :var-attr:`unused` attribute
1687 (see :ref:`variable-attributes`).
1689 .. option:: -Wno-unused-parameter
1691 Default setting; overrides :option:`-Wunused-parameter`.
1693 .. option:: -Wno-unused-result
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`.
1699 .. option:: -Wunused-result
1701 Default setting; overrides :option:`-Wno-unused-result`.
1703 .. option:: -Wunused-variable
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`.
1709 To suppress this warning use the :var-attr:`unused` attribute
1710 (see :ref:`variable-attributes`).
1712 .. option:: -Wno-unused-variable
1714 Default setting; overrides :option:`-Wunused-variable`.
1716 .. option:: -Wunused-const-variable, -Wunused-const-variable={n}
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.
1723 To suppress this warning use the :var-attr:`unused` attribute
1724 (see :ref:`variable-attributes`).
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
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
1739 .. option:: -Wno-unused-const-variable
1741 Default setting; overrides :option:`-Wunused-const-variable`.
1743 .. option:: -Wunused-value
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.
1752 This warning is enabled by :option:`-Wall`.
1754 .. option:: -Wno-unused-value
1756 Default setting; overrides :option:`-Wunused-value`.
1758 .. option:: -Wunused
1760 All the above :option:`-Wunused` options combined.
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`.
1766 .. option:: -Wno-unused
1768 Default setting; overrides :option:`-Wunused`.
1770 .. option:: -Wuninitialized
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
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.)
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.
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
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
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:
1810 .. option:: -Wno-uninitialized
1812 Default setting; overrides :option:`-Wuninitialized`.
1814 .. option:: -Wno-invalid-memory-model
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:
1829 __atomic_store_n (i, 0, memory_order_consume);
1832 :option:`-Winvalid-memory-model` is enabled by default.
1834 .. option:: -Winvalid-memory-model
1836 Default setting; overrides :option:`-Wno-invalid-memory-model`.
1838 .. option:: -Wmaybe-uninitialized
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.
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`).
1853 These warnings are only possible in optimizing compilation, because otherwise
1854 GCC does not keep track of the state of variables.
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:
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
1880 .. index:: longjmp warnings
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.
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`.
1893 This warning is enabled by :option:`-Wall` or :option:`-Wextra`.
1895 .. option:: -Wno-maybe-uninitialized
1897 Default setting; overrides :option:`-Wmaybe-uninitialized`.
1899 .. index:: warning for unknown pragmas, unknown pragmas, warning, pragmas, warning of unknown
1901 .. option:: -Wunknown-pragmas
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.
1908 .. option:: -Wno-unknown-pragmas
1910 Default setting; overrides :option:`-Wunknown-pragmas`.
1912 .. option:: -Wno-pragmas
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`.
1918 .. option:: -Wpragmas
1920 Default setting; overrides :option:`-Wno-pragmas`.
1922 .. option:: -Wno-prio-ctor-dtor
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
1931 .. option:: -Wprio-ctor-dtor
1933 Default setting; overrides :option:`-Wno-prio-ctor-dtor`.
1935 .. option:: -Wstrict-aliasing
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`
1944 .. option:: -Wno-strict-aliasing
1946 Default setting; overrides :option:`-Wstrict-aliasing`.
1948 .. option:: -Wstrict-aliasing=n
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`
1956 :option:`-Wstrict-aliasing` is equivalent to :option:`-Wstrict-aliasing=3`.
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.
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.
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.
1981 .. option:: -Wstrict-overflow, -Wstrict-overflow={n}
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.
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
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.
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`.
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``.
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``.
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
2031 .. option:: -Wno-strict-overflow
2033 Default setting; overrides :option:`-Wstrict-overflow`.
2035 .. option:: -Wstring-compare
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``.
2050 strcpy (d, "string");
2052 if (0 == strcmp (a, d)) // cannot be true
2053 puts ("a and d are the same");
2056 :option:`-Wstring-compare` is enabled by :option:`-Wextra`.
2058 .. option:: -Wno-string-compare
2060 Default setting; overrides :option:`-Wstring-compare`.
2062 .. option:: -Wstringop-overflow, -Wstringop-overflow={type}
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
2084 enum Color { blue, purple, yellow };
2085 const char* f (enum Color clr)
2087 static char buf [4];
2091 case blue: str = "blue"; break;
2092 case purple: str = "purple"; break;
2093 case yellow: str = "yellow"; break;
2096 return strcpy (buf, str); // warning here
2099 Option :option:`-Wstringop-overflow=2` is enabled by default.
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.
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.
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
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.
2135 .. option:: -Wno-stringop-overflow
2137 Default setting; overrides :option:`-Wstringop-overflow`.
2139 .. option:: -Wno-stringop-overread
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
2145 Option :option:`-Wstringop-overread` is enabled by default.
2147 .. option:: -Wstringop-overread
2149 Default setting; overrides :option:`-Wno-stringop-overread`.
2151 .. option:: -Wno-stringop-truncation
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.
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.
2165 void append (char *buf, size_t bufsize)
2167 strncat (buf, ".txt", 3);
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.
2179 void copy (char *d, const char *s)
2181 strncpy (d, s, strlen (s));
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``.
2193 void copy (const char *s)
2196 strncpy (buf, s, sizeof buf);
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`.
2208 .. option:: -Wstringop-truncation
2210 Default setting; overrides :option:`-Wno-stringop-truncation`.
2212 .. option:: -Wsuggest-attribute=[pure|const|noreturn|format|cold|malloc]
2214 Warn for cases where adding an attribute may be beneficial. The
2215 attributes currently supported are listed below.
2217 .. option:: -Wsuggest-attribute=pure, -Wno-suggest-attribute=pure, -Wno-suggest-attribute=const, -Wno-suggest-attribute=noreturn, -Wno-missing-noreturn, -Wno-suggest-attribute=malloc
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
2229 .. option:: -Wsuggest-attribute=format, -Wno-suggest-attribute=format, -Wno-missing-format-attribute
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.
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.
2249 .. option:: -Wsuggest-attribute=cold
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``.
2256 .. option:: -Wno-suggest-attribute=cold
2258 Default setting; overrides :option:`-Wsuggest-attribute=cold`.
2260 .. option:: -Walloc-zero
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.
2270 .. option:: -Wno-alloc-zero
2272 Default setting; overrides :option:`-Walloc-zero`.
2274 .. option:: -Walloc-size-larger-than={byte-size}
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`.
2286 .. option:: -Wno-alloc-size-larger-than
2288 Disable :option:`-Walloc-size-larger-than=` warnings. The option is
2289 equivalent to :option:`-Walloc-size-larger-than=SIZE_MAX` or
2292 .. option:: -Walloca
2294 This option warns on all uses of ``alloca`` in the source.
2296 .. option:: -Wno-alloca
2298 Default setting; overrides :option:`-Walloca`.
2300 .. option:: -Walloca-larger-than={byte-size}
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
2309 For example, a bounded case of ``alloca`` could be:
2313 void func (size_t n)
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.
2328 Unbounded uses, on the other hand, are uses of ``alloca`` with no
2329 controlling predicate constraining its integer argument. For example:
2335 void *p = alloca (n);
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.
2342 Note, that even seemingly correct code involving signed integers could
2347 void func (signed int n)
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.
2359 This option also warns when ``alloca`` is used in a loop.
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).
2365 See also :option:`-Wvla-larger-than=byte-size`.
2367 .. option:: -Wno-alloca-larger-than
2369 Disable :option:`-Walloca-larger-than=` warnings. The option is
2370 equivalent to :option:`-Walloca-larger-than=SIZE_MAX` or larger.
2372 .. option:: -Warith-conversion
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`.
2381 void f (char c, int i)
2383 c = c + i; // warns with -Wconversion
2384 c = c + 1; // only warns with -Warith-conversion
2387 .. option:: -Wno-arith-conversion
2389 Default setting; overrides :option:`-Warith-conversion`.
2391 .. option:: -Warray-bounds, -Warray-bounds={n}
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.
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.
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.
2409 .. option:: -Wno-array-bounds
2411 Default setting; overrides :option:`-Warray-bounds`.
2413 .. option:: -Warray-compare
2415 Warn about equality and relational comparisons between two operands of array
2416 type. This comparison was deprecated in C++20. For example:
2422 bool same = arr1 == arr2;
2424 :option:`-Warray-compare` is enabled by :option:`-Wall`.
2426 .. option:: -Wno-array-compare
2428 Default setting; overrides :option:`-Warray-compare`.
2430 .. option:: -Warray-parameter, -Warray-parameter={n}
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`.
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.
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.
2452 void f (int[static 4]);
2453 void f (int[]); // warning (inconsistent array form)
2457 int *p = (int *)malloc (4);
2458 f (p); // warning (array too small)
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.
2470 void g (int[]); // no warning
2471 void g (int[8]); // warning (inconsistent array bound)
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.
2477 .. option:: -Wno-array-parameter
2479 Default setting; overrides :option:`-Warray-parameter`.
2481 .. option:: -Wattribute-alias={n}
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`.
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.
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.
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`.
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`.
2511 .. option:: -Wattribute-alias
2513 Default setting; overrides :option:`-Wno-attribute-alias`.
2515 .. option:: -Wbidi-chars=[none|unpaired|any|ucn]
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.
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
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.
2536 .. option:: -Wbool-compare
2538 Warn about boolean expression compared with an integer value different from
2539 ``true`` / ``false``. For instance, the following comparison is
2546 if ((n > 1) == 2) { ... }
2548 This warning is enabled by :option:`-Wall`.
2550 .. option:: -Wno-bool-compare
2552 Default setting; overrides :option:`-Wbool-compare`.
2554 .. option:: -Wbool-operation
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.)
2562 This warning is enabled by :option:`-Wall`.
2564 .. option:: -Wno-bool-operation
2566 Default setting; overrides :option:`-Wbool-operation`.
2568 .. option:: -Wduplicated-branches
2570 Warn when an if-else has identical branches. This warning detects cases like
2579 It doesn't warn when both branches contain just a null statement. This warning
2580 also warn for conditional operators:
2584 int i = x ? *p : *p;
2586 .. option:: -Wno-duplicated-branches
2588 Default setting; overrides :option:`-Wduplicated-branches`.
2590 .. option:: -Wduplicated-cond
2592 Warn about duplicated conditions in an if-else-if chain. For instance,
2593 warn for the following code:
2597 if (p->q != NULL) { ... }
2598 else if (p->q != NULL) { ... }
2600 .. option:: -Wno-duplicated-cond
2602 Default setting; overrides :option:`-Wduplicated-cond`.
2604 .. option:: -Wframe-address
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`.
2610 .. option:: -Wno-frame-address
2612 Default setting; overrides :option:`-Wframe-address`.
2614 .. option:: -Wno-discarded-qualifiers
2618 C and Objective-C only
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.
2625 .. option:: -Wdiscarded-qualifiers
2627 Default setting; overrides :option:`-Wno-discarded-qualifiers`.
2629 .. option:: -Wno-discarded-array-qualifiers
2633 C and Objective-C only
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.
2641 .. option:: -Wdiscarded-array-qualifiers
2643 Default setting; overrides :option:`-Wno-discarded-array-qualifiers`.
2645 .. option:: -Wno-incompatible-pointer-types
2649 C and Objective-C only
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
2656 .. option:: -Wincompatible-pointer-types
2658 Default setting; overrides :option:`-Wno-incompatible-pointer-types`.
2660 .. option:: -Wno-int-conversion
2664 C and Objective-C only
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.
2671 .. option:: -Wint-conversion
2673 Default setting; overrides :option:`-Wno-int-conversion`.
2675 .. option:: -Wzero-length-bounds
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`.
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.
2689 struct X { int a[0]; int b, c; };
2694 x.a[0] = 0; // -Wzero-length-bounds
2695 x.a[1] = 1; // -Wzero-length-bounds
2696 x.a[2] = 2; // -Warray-bounds
2699 Option :option:`-Wzero-length-bounds` is enabled by :option:`-Warray-bounds`.
2701 .. option:: -Wno-div-by-zero
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.
2707 .. option:: -Wdiv-by-zero
2709 Default setting; overrides :option:`-Wno-div-by-zero`.
2711 .. index:: warnings from system headers, system headers, warnings from
2713 .. option:: -Wsystem-headers
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.
2724 .. option:: -Wno-system-headers
2726 Default setting; overrides :option:`-Wsystem-headers`.
2728 .. option:: -Wtautological-compare
2730 Warn if a self-comparison always evaluates to true or false. This
2731 warning detects various mistakes such as:
2739 This warning also warns about bitwise comparisons that always evaluate
2740 to true or false, for instance:
2744 if ((a & 16) == 10) { ... }
2746 will always be false.
2748 This warning is enabled by :option:`-Wall`.
2750 .. option:: -Wno-tautological-compare
2752 Default setting; overrides :option:`-Wtautological-compare`.
2754 .. option:: -Wtrampolines
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.
2764 .. option:: -Wno-trampolines
2766 Default setting; overrides :option:`-Wtrampolines`.
2768 .. option:: -Wfloat-equal
2770 Warn if floating-point values are used in equality comparisons.
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
2783 .. option:: -Wno-float-equal
2785 Default setting; overrides :option:`-Wfloat-equal`.
2787 .. option:: -Wtraditional
2791 C and Objective-C only
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.
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.
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.
2811 * A function-like macro that appears without arguments.
2813 * The unary plus operator.
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.
2823 * A function declared external in one block and then used after the end of
2826 * A ``switch`` statement has an operand of type ``long``.
2828 * A non- ``static`` function declaration follows a ``static`` one.
2829 This construct is not accepted by some traditional C compilers.
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.
2836 * Usage of ISO string concatenation is detected.
2838 * Initialization of automatic aggregates.
2840 * Identifier conflicts with labels. Traditional C lacks a separate
2841 namespace for labels.
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
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`.
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.
2862 .. option:: -Wno-traditional
2864 Default setting; overrides :option:`-Wtraditional`.
2866 .. option:: -Wtraditional-conversion
2870 C and Objective-C only
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.
2878 .. option:: -Wno-traditional-conversion
2880 Default setting; overrides :option:`-Wtraditional-conversion`.
2882 .. option:: -Wdeclaration-after-statement
2886 C and Objective-C only
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`.
2892 .. option:: -Wno-declaration-after-statement
2894 Default setting; overrides :option:`-Wdeclaration-after-statement`.
2896 .. option:: -Wshadow
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`.
2909 .. option:: -Wno-shadow
2911 Default setting; overrides :option:`-Wshadow`.
2913 .. option:: -Wno-shadow-ivar
2919 Do not warn whenever a local variable shadows an instance variable in an
2922 .. option:: -Wshadow-ivar
2924 Default setting; overrides :option:`-Wno-shadow-ivar`.
2926 .. option:: -Wshadow=global
2928 Warn for any shadowing.
2929 Same as :option:`-Wshadow`.
2931 .. option:: -Wshadow=local
2933 Warn when a local variable shadows another local variable or parameter.
2935 .. option:: -Wshadow=compatible-local
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:
2947 for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
2949 for (int i = 0; i < N; ++i)
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.
2965 This warning is also enabled by :option:`-Wshadow=local`.
2967 .. index:: Wlarger-than-byte-size
2969 .. option:: -Wlarger-than={byte-size}
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`.
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`.
2981 .. option:: -Wno-larger-than
2983 Disable :option:`-Wlarger-than=` warnings. The option is equivalent
2984 to :option:`-Wlarger-than=SIZE_MAX` or larger.
2986 .. option:: -Wframe-larger-than={byte-size}
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`.
3001 .. option:: -Wno-frame-larger-than
3003 Disable :option:`-Wframe-larger-than=` warnings. The option is equivalent
3004 to :option:`-Wframe-larger-than=SIZE_MAX` or larger.
3006 .. option:: -Wfree-nonheap-object
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
3019 p = stpcpy (p, "abc");
3021 free (p); // warning
3024 :option:`-Wfree-nonheap-object` is included in :option:`-Wall`.
3026 .. option:: -Wno-free-nonheap-object
3028 Default setting; overrides :option:`-Wfree-nonheap-object`.
3030 .. option:: -Wstack-usage={byte-size}
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
3038 The message is in keeping with the output of :option:`-fstack-usage`.
3040 * If the stack usage is fully static but exceeds the specified amount, it's:
3044 warning: stack usage is 1120 bytes
3046 * If the stack usage is (partly) dynamic but bounded, it's:
3050 warning: stack usage might be 1648 bytes
3052 * If the stack usage is (partly) dynamic and not bounded, it's:
3056 warning: stack usage might be unbounded
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`.
3063 .. option:: -Wno-stack-usage
3065 Disable :option:`-Wstack-usage=` warnings. The option is equivalent
3066 to :option:`-Wstack-usage=SIZE_MAX` or larger.
3068 .. option:: -Wunsafe-loop-optimizations
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
3075 .. option:: -Wno-unsafe-loop-optimizations
3077 Default setting; overrides :option:`-Wunsafe-loop-optimizations`.
3079 .. option:: -Wno-pedantic-ms-format
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.
3091 .. option:: -Wpedantic-ms-format
3093 Default setting; overrides :option:`-Wno-pedantic-ms-format`.
3095 .. option:: -Wpointer-arith
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`.
3103 .. option:: -Wno-pointer-arith
3105 Default setting; overrides :option:`-Wpointer-arith`.
3107 .. option:: -Wno-pointer-compare
3109 Do not warn if a pointer is compared with a zero character constant.
3111 means that the pointer was meant to be dereferenced. For example:
3115 const char *p = foo ();
3119 Note that the code above is invalid in C++11.
3121 This warning is enabled by default.
3123 .. option:: -Wpointer-compare
3125 Default setting; overrides :option:`-Wno-pointer-compare`.
3129 Warn about unsupported features in ThreadSanitizer.
3131 ThreadSanitizer does not support ``std::atomic_thread_fence`` and
3132 can report false positives.
3134 This warning is enabled by default.
3136 .. option:: -Wno-tsan
3138 Default setting; overrides :option:`-Wtsan`.
3140 .. option:: -Wtype-limits
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
3148 .. option:: -Wno-type-limits
3150 Default setting; overrides :option:`-Wtype-limits`.
3152 .. option:: -Wabsolute-value
3156 C and Objective-C only
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`.
3167 .. option:: -Wno-absolute-value
3169 Default setting; overrides :option:`-Wabsolute-value`.
3171 .. include:: ../../../../doc/cppwarnopts.rst
3174 .. option:: -Wendif-labels
3176 Default setting; overrides :option:`-Wno-endif-labels`.
3178 .. option:: -Wbad-function-cast
3182 C and Objective-C only
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.
3188 .. option:: -Wno-bad-function-cast
3190 Default setting; overrides :option:`-Wbad-function-cast`.
3192 .. option:: -Wc90-c99-compat
3196 C and Objective-C only
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__``.
3204 .. option:: -Wno-c90-c99-compat
3206 Default setting; overrides :option:`-Wc90-c99-compat`.
3208 .. option:: -Wc99-c11-compat
3212 C and Objective-C only
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__``.
3221 .. option:: -Wno-c99-c11-compat
3223 Default setting; overrides :option:`-Wc99-c11-compat`.
3225 .. option:: -Wc11-c2x-compat
3229 C and Objective-C only
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
3238 .. option:: -Wno-c11-c2x-compat
3240 Default setting; overrides :option:`-Wc11-c2x-compat`.
3242 .. option:: -Wc++-compat
3246 C and Objective-C only
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.
3252 .. option:: -Wno-c++-compat
3254 Default setting; overrides :option:`-Wc++-compat`.
3256 .. option:: -Wc++11-compat
3260 C++ and Objective-C++ only
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`.
3267 .. option:: -Wno-c++11-compat
3269 Default setting; overrides :option:`-Wc++11-compat`.
3271 .. option:: -Wc++14-compat
3275 C++ and Objective-C++ only
3277 Warn about C++ constructs whose meaning differs between ISO C++ 2011
3278 and ISO C++ 2014. This warning is enabled by :option:`-Wall`.
3280 .. option:: -Wno-c++14-compat
3282 Default setting; overrides :option:`-Wc++14-compat`.
3284 .. option:: -Wc++17-compat
3288 C++ and Objective-C++ only
3290 Warn about C++ constructs whose meaning differs between ISO C++ 2014
3291 and ISO C++ 2017. This warning is enabled by :option:`-Wall`.
3293 .. option:: -Wno-c++17-compat
3295 Default setting; overrides :option:`-Wc++17-compat`.
3297 .. option:: -Wc++20-compat
3301 C++ and Objective-C++ only
3303 Warn about C++ constructs whose meaning differs between ISO C++ 2017
3304 and ISO C++ 2020. This warning is enabled by :option:`-Wall`.
3306 .. option:: -Wno-c++20-compat
3308 Default setting; overrides :option:`-Wc++20-compat`.
3310 .. option:: -Wno-c++11-extensions
3314 C++ and Objective-C++ only
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.
3320 .. option:: -Wc++11-extensions
3322 Default setting; overrides :option:`-Wno-c++11-extensions`.
3324 .. option:: -Wno-c++14-extensions
3328 C++ and Objective-C++ only
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.
3334 .. option:: -Wc++14-extensions
3336 Default setting; overrides :option:`-Wno-c++14-extensions`.
3338 .. option:: -Wno-c++17-extensions
3342 C++ and Objective-C++ only
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.
3348 .. option:: -Wc++17-extensions
3350 Default setting; overrides :option:`-Wno-c++17-extensions`.
3352 .. option:: -Wno-c++20-extensions
3356 C++ and Objective-C++ only
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.
3362 .. option:: -Wc++20-extensions
3364 Default setting; overrides :option:`-Wno-c++20-extensions`.
3366 .. option:: -Wno-c++23-extensions
3370 C++ and Objective-C++ only
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.
3376 .. option:: -Wc++23-extensions
3378 Default setting; overrides :option:`-Wno-c++23-extensions`.
3380 .. option:: -Wcast-qual
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 *``.
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:
3392 /* p is char ** value. */
3393 const char **q = (const char **) p;
3394 /* Assignment of readonly string to const char * is OK. */
3396 /* Now char** pointer points to read-only memory. */
3399 .. option:: -Wno-cast-qual
3401 Default setting; overrides :option:`-Wcast-qual`.
3403 .. option:: -Wcast-align
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.
3410 .. option:: -Wno-cast-align
3412 Default setting; overrides :option:`-Wcast-align`.
3414 .. option:: -Wcast-align=strict
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.
3420 .. option:: -Wcast-function-type
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`.
3434 .. option:: -Wno-cast-function-type
3436 Default setting; overrides :option:`-Wcast-function-type`.
3438 .. option:: -Wwrite-strings
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
3449 When compiling C++, warn about the deprecated conversion from string
3450 literals to ``char *``. This warning is enabled by default for C++
3453 .. option:: -Wno-write-strings
3455 Default setting; overrides :option:`-Wwrite-strings`.
3457 .. option:: -Wclobbered
3459 Warn for variables that might be changed by ``longjmp`` or
3460 ``vfork``. This warning is also enabled by :option:`-Wextra`.
3462 .. option:: -Wno-clobbered
3464 Default setting; overrides :option:`-Wclobbered`.
3466 .. option:: -Wconversion
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`.
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.
3485 Warnings about conversion from arithmetic on a small type back to that
3486 type are only given with :option:`-Warith-conversion`.
3488 .. option:: -Wno-conversion
3490 Default setting; overrides :option:`-Wconversion`.
3492 .. option:: -Wdangling-else
3494 Warn about constructions where there may be confusion to which
3495 ``if`` statement an ``else`` branch belongs. Here is an example of
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
3530 This warning is enabled by :option:`-Wparentheses`.
3532 .. option:: -Wno-dangling-else
3534 Default setting; overrides :option:`-Wdangling-else`.
3536 .. option:: -Wdangling-pointer, -Wdangling-pointer={n}
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.
3545 ``-Wdangling-pointer=1``
3546 At level 1 the warning diagnoses only unconditional uses of dangling pointers.
3551 int f (int c1, int c2, x)
3553 char *p = strchr ((char[]){ c1, c2 }, c3);
3554 return p ? *p : 'x'; // warning: dangling pointer to a compound literal
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.
3565 *p = &x; // warning: storing the address of a local variable in *p
3568 ``-Wdangling-pointer=2``
3569 At level 2, in addition to unconditional uses the warning also diagnoses
3570 conditional uses of dangling pointers.
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.
3582 char a[12] = "tmpname";
3585 strcat (s, ".tmp"); // warning: dangling pointer to a may be used
3589 :option:`-Wdangling-pointer=2` is included in :option:`-Wall`.
3591 .. option:: -Wno-dangling-pointer
3593 Default setting; overrides :option:`-Wdangling-pointer`.
3595 .. option:: -Wdate-time
3597 Warn when macros ``__TIME__``, ``__DATE__`` or ``__TIMESTAMP__``
3598 are encountered as they might prevent bit-wise-identical reproducible
3601 .. option:: -Wno-date-time
3603 Default setting; overrides :option:`-Wdate-time`.
3605 .. option:: -Wempty-body
3607 Warn if an empty body occurs in an ``if``, ``else`` or ``do
3608 while`` statement. This warning is also enabled by :option:`-Wextra`.
3610 .. option:: -Wno-empty-body
3612 Default setting; overrides :option:`-Wempty-body`.
3614 .. option:: -Wno-endif-labels
3616 Do not warn about stray tokens after ``#else`` and ``#endif``.
3618 .. option:: -Wendif-labels
3620 Default setting; overrides :option:`-Wno-endif-labels`.
3622 .. option:: -Wenum-compare
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`.
3629 .. option:: -Wno-enum-compare
3631 Default setting; overrides :option:`-Wenum-compare`.
3633 .. option:: -Wenum-conversion
3635 Warn when a value of enumerated type is implicitly converted to a
3636 different enumerated type. This warning is enabled by :option:`-Wextra`
3639 .. option:: -Wno-enum-conversion
3641 Default setting; overrides :option:`-Wenum-conversion`.
3643 .. option:: -Wenum-int-mismatch
3647 C and Objective-C only
3649 Warn about mismatches between an enumerated type and an integer type in
3650 declarations. For example:
3654 enum E { l = -1, z = 0, g = 1 };
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`.
3665 .. option:: -Wno-enum-int-mismatch
3667 Default setting; overrides :option:`-Wenum-int-mismatch`.
3669 .. option:: -Wjump-misses-init
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
3682 :option:`-Wjump-misses-init` is included in :option:`-Wc++-compat`. It
3683 can be disabled with the :option:`-Wno-jump-misses-init` option.
3685 .. option:: -Wno-jump-misses-init
3687 Default setting; overrides :option:`-Wjump-misses-init`.
3689 .. index:: warning for comparison of signed and unsigned values, comparison of signed and unsigned values, warning, signed and unsigned values, comparison warning
3691 .. option:: -Wsign-compare
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`.
3698 .. option:: -Wno-sign-compare
3700 Default setting; overrides :option:`-Wsign-compare`.
3702 .. option:: -Wsign-conversion
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`.
3709 .. option:: -Wno-sign-conversion
3711 Default setting; overrides :option:`-Wsign-conversion`.
3713 .. option:: -Wfloat-conversion
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`.
3720 .. option:: -Wno-float-conversion
3722 Default setting; overrides :option:`-Wfloat-conversion`.
3724 .. option:: -Wno-scalar-storage-order
3726 Do not warn on suspicious constructs involving reverse scalar storage order.
3728 .. option:: -Wscalar-storage-order
3730 Default setting; overrides :option:`-Wno-scalar-storage-order`.
3732 .. option:: -Wsizeof-array-div
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
3744 return sizeof (arr) / sizeof (short);
3747 This warning is enabled by :option:`-Wall`.
3749 .. option:: -Wno-sizeof-array-div
3751 Default setting; overrides :option:`-Wsizeof-array-div`.
3753 .. option:: -Wsizeof-pointer-div
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`.
3761 .. option:: -Wno-sizeof-pointer-div
3763 Default setting; overrides :option:`-Wsizeof-pointer-div`.
3765 .. option:: -Wsizeof-pointer-memaccess
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.
3780 void make_file (const char *name)
3782 char path[PATH_MAX];
3783 strncpy (path, name, sizeof path - 1);
3784 strncat (path, ".text", sizeof ".text");
3788 The :option:`-Wsizeof-pointer-memaccess` option is enabled by :option:`-Wall`.
3790 .. option:: -Wno-sizeof-pointer-memaccess
3792 Default setting; overrides :option:`-Wsizeof-pointer-memaccess`.
3794 .. option:: -Wno-sizeof-array-argument
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.
3800 .. option:: -Wsizeof-array-argument
3802 Default setting; overrides :option:`-Wno-sizeof-array-argument`.
3804 .. option:: -Wmemset-elt-size
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`.
3812 .. option:: -Wno-memset-elt-size
3814 Default setting; overrides :option:`-Wmemset-elt-size`.
3816 .. option:: -Wmemset-transposed-args
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
3828 .. option:: -Wno-memset-transposed-args
3830 Default setting; overrides :option:`-Wmemset-transposed-args`.
3832 .. option:: -Waddress
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
3843 if (!f) // warning: expression evaluates to false
3847 comparisons of a pointer to a string literal, such as in
3851 void f (const char *x)
3853 if (x == "abc") // warning: expression evaluates to false
3857 and tests of the results of pointer addition or subtraction for equality
3862 void f (const int *p, int i)
3864 return p + i == NULL;
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
3878 :option:`-Waddress` warning is enabled by :option:`-Wall`.
3880 .. option:: -Wno-address
3882 Default setting; overrides :option:`-Waddress`.
3884 .. option:: -Wno-address-of-packed-member
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
3890 .. option:: -Waddress-of-packed-member
3892 Default setting; overrides :option:`-Wno-address-of-packed-member`.
3894 .. option:: -Wlogical-op
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:
3904 if (a < 0 && a < 0) { ... }
3906 .. option:: -Wno-logical-op
3908 Default setting; overrides :option:`-Wlogical-op`.
3910 .. option:: -Wlogical-not-parentheses
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:
3922 It is possible to suppress the warning by wrapping the LHS into
3927 if ((!a) > 1) { ... }
3929 This warning is enabled by :option:`-Wall`.
3931 .. option:: -Wno-logical-not-parentheses
3933 Default setting; overrides :option:`-Wlogical-not-parentheses`.
3935 .. option:: -Waggregate-return
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
3941 .. option:: -Wno-aggregate-return
3943 Default setting; overrides :option:`-Waggregate-return`.
3945 .. option:: -Wno-aggressive-loop-optimizations
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.
3950 .. option:: -Waggressive-loop-optimizations
3952 Default setting; overrides :option:`-Wno-aggressive-loop-optimizations`.
3954 .. option:: -Wno-attributes
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
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
3968 [[vendor::attr]] void f();
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:
3976 [[vendor::safe]] void f();
3977 [[vendor::unsafe]] void f2();
3979 Note that :option:`-Wno-attributes=` does not imply :option:`-Wno-attributes`.
3981 .. option:: -Wattributes
3983 Default setting; overrides :option:`-Wno-attributes`.
3985 .. option:: -Wno-builtin-declaration-mismatch
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.
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.
4003 extern void* memset ();
4006 memset (d, '\0', 32);
4009 .. option:: -Wbuiltin-declaration-mismatch
4011 Default setting; overrides :option:`-Wno-builtin-declaration-mismatch`.
4013 .. option:: -Wno-builtin-macro-redefined
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__``.
4019 .. option:: -Wbuiltin-macro-redefined
4021 Default setting; overrides :option:`-Wno-builtin-macro-redefined`.
4023 .. option:: -Wstrict-prototypes
4027 C and Objective-C only
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
4034 .. option:: -Wno-strict-prototypes
4036 Default setting; overrides :option:`-Wstrict-prototypes`.
4038 .. option:: -Wold-style-declaration
4042 C and Objective-C only
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`.
4049 .. option:: -Wno-old-style-declaration
4051 Default setting; overrides :option:`-Wold-style-declaration`.
4053 .. option:: -Wold-style-definition
4057 C and Objective-C only
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.
4065 .. option:: -Wno-old-style-definition
4067 Default setting; overrides :option:`-Wold-style-definition`.
4069 .. option:: -Wmissing-parameter-type
4073 C and Objective-C only
4075 A function parameter is declared without a type specifier in K&R-style
4082 This warning is also enabled by :option:`-Wextra`.
4084 .. option:: -Wno-missing-parameter-type
4086 Default setting; overrides :option:`-Wmissing-parameter-type`.
4088 .. option:: -Wmissing-prototypes
4092 C and Objective-C only
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++.
4103 .. option:: -Wno-missing-prototypes
4105 Default setting; overrides :option:`-Wmissing-prototypes`.
4107 .. option:: -Wmissing-declarations
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.
4117 .. option:: -Wno-missing-declarations
4119 Default setting; overrides :option:`-Wmissing-declarations`.
4121 .. option:: -Wmissing-field-initializers
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:
4129 struct s { int f, g, h; };
4130 struct s x = { 3, 4 };
4132 This option does not warn about designated initializers, so the following
4133 modification does not trigger a warning:
4137 struct s { int f, g, h; };
4138 struct s x = { .f = 3, .g = 4 };
4140 In C this option does not warn about the universal zero initializer
4145 struct s { int f, g, h; };
4148 Likewise, in C++ this option does not warn about the empty { }
4149 initializer, for example:
4153 struct s { int f, g, h; };
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`.
4159 .. option:: -Wno-missing-field-initializers
4161 Default setting; overrides :option:`-Wmissing-field-initializers`.
4163 .. option:: -Wno-missing-requires
4165 By default, the compiler warns about a concept-id appearing as a C++20 simple-requirement:
4169 bool satisfied = requires { C<T> };
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
4176 bool satisfied = requires { requires C<T> };
4178 so :samp:`satisfied` is only true if concept :samp:`C` is satisfied for
4181 This warning can be disabled with :option:`-Wno-missing-requires`.
4183 .. option:: -Wmissing-requires
4185 Default setting; overrides :option:`-Wno-missing-requires`.
4187 .. option:: -Wno-missing-template-keyword
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
4198 x.template DoSomeOtherStuff<X>(); // Good.
4199 x.DoMoreStuff<X>(); // Warning, x is dependent.
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:
4208 void NotATemplate (my_class t)
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.
4216 This warning can be disabled with :option:`-Wno-missing-template-keyword`.
4218 .. option:: -Wmissing-template-keyword
4220 Default setting; overrides :option:`-Wno-missing-template-keyword`.
4222 .. option:: -Wno-multichar
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.
4228 .. option:: -Wmultichar
4230 Default setting; overrides :option:`-Wno-multichar`.
4232 .. index:: NFC, NFKC, character set, input normalization
4234 .. option:: -Wnormalized=[none|id|nfc|nfkc]
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.
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`.
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.
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.
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.
4278 .. option:: -Wno-attribute-warning
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.
4286 .. option:: -Wattribute-warning
4288 Default setting; overrides :option:`-Wno-attribute-warning`.
4290 .. option:: -Wno-deprecated
4292 Do not warn about usage of deprecated features. See :ref:`deprecated-features`.
4294 .. option:: -Wdeprecated
4296 Default setting; overrides :option:`-Wno-deprecated`.
4298 .. option:: -Wno-deprecated-declarations
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``
4304 .. option:: -Wdeprecated-declarations
4306 Default setting; overrides :option:`-Wno-deprecated-declarations`.
4308 .. option:: -Wno-overflow
4310 Do not warn about compile-time overflow in constant expressions.
4312 .. option:: -Woverflow
4314 Default setting; overrides :option:`-Wno-overflow`.
4316 .. option:: -Wno-odr
4318 Warn about One Definition Rule violations during link-time optimization.
4323 Default setting; overrides :option:`-Wno-odr`.
4325 .. index:: OpenACC accelerator programming
4327 .. option:: -Wopenacc-parallelism
4329 Warn about potentially suboptimal choices related to OpenACC parallelism.
4331 .. option:: -Wno-openacc-parallelism
4333 Default setting; overrides :option:`-Wopenacc-parallelism`.
4335 .. option:: -Wopenmp-simd
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.
4341 .. option:: -Wno-openmp-simd
4343 Default setting; overrides :option:`-Wopenmp-simd`.
4345 .. option:: -Woverride-init
4349 C and Objective-C only
4351 Warn if an initialized field without side effects is overridden when
4352 using designated initializers (see :ref:`designated-inits`).
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`.
4358 .. option:: -Wno-override-init
4360 Default setting; overrides :option:`-Woverride-init`.
4362 .. option:: -Wno-override-init-side-effects
4366 C and Objective-C only
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.
4371 .. option:: -Woverride-init-side-effects
4373 Default setting; overrides :option:`-Wno-override-init-side-effects`.
4375 .. option:: -Wpacked
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:
4389 } __attribute__((packed));
4395 .. option:: -Wno-packed
4397 Default setting; overrides :option:`-Wpacked`.
4399 .. option:: -Wnopacked-bitfield-compat
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:
4414 } __attribute__ ((packed));
4416 This warning is enabled by default. Use
4417 :option:`-Wno-packed-bitfield-compat` to disable this warning.
4419 .. option:: -Wpacked-not-aligned
4423 C, C++, Objective-C and Objective-C++ only
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:
4432 struct __attribute__ ((aligned (8))) S8 { char a[8]; };
4433 struct __attribute__ ((packed)) S {
4437 This warning is enabled by :option:`-Wall`.
4439 .. option:: -Wno-packed-not-aligned
4441 Default setting; overrides :option:`-Wpacked-not-aligned`.
4443 .. option:: -Wpadded
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.
4450 .. option:: -Wno-padded
4452 Default setting; overrides :option:`-Wpadded`.
4454 .. option:: -Wredundant-decls
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.
4459 .. option:: -Wno-redundant-decls
4461 Default setting; overrides :option:`-Wredundant-decls`.
4463 .. option:: -Wrestrict
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.
4477 char a[] = "abcd1234";
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`.
4486 .. option:: -Wno-restrict
4488 Default setting; overrides :option:`-Wrestrict`.
4490 .. option:: -Wnested-externs
4494 C and Objective-C only
4496 Warn if an ``extern`` declaration is encountered within a function.
4498 .. option:: -Wno-nested-externs
4500 Default setting; overrides :option:`-Wnested-externs`.
4502 .. option:: -Winline
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.
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.
4515 .. option:: -Wno-inline
4517 Default setting; overrides :option:`-Winline`.
4519 .. option:: -Winterference-size
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.
4525 This variable is intended to be used for controlling class layout, to
4526 avoid false sharing in concurrent code:
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;
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
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`).
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`.
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`.
4556 .. option:: -Wint-in-bool-context
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`.
4565 .. option:: -Wno-int-in-bool-context
4567 Default setting; overrides :option:`-Wint-in-bool-context`.
4569 .. option:: -Wno-int-to-pointer-cast
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.
4575 .. option:: -Wint-to-pointer-cast
4577 Default setting; overrides :option:`-Wno-int-to-pointer-cast`.
4579 .. option:: -Wno-pointer-to-int-cast
4583 C and Objective-C only
4585 Suppress warnings from casts from a pointer to an integer type of a
4588 .. option:: -Wpointer-to-int-cast
4590 Default setting; overrides :option:`-Wno-pointer-to-int-cast`.
4592 .. option:: -Winvalid-pch
4594 Warn if a precompiled header (see :ref:`precompiled-headers`) is found in
4595 the search path but cannot be used.
4597 .. option:: -Wno-invalid-pch
4599 Default setting; overrides :option:`-Winvalid-pch`.
4601 .. option:: -Winvalid-utf8
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`.
4607 .. option:: -Wno-invalid-utf8
4609 Default setting; overrides :option:`-Winvalid-utf8`.
4611 .. option:: -Wno-unicode
4613 Don't diagnose invalid forms of delimited or named escape sequences which are
4614 treated as separate tokens. Wunicode is enabled by default.
4616 .. option:: -Wunicode
4618 Default setting; overrides :option:`-Wno-unicode`.
4620 .. option:: -Wlong-long
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`.
4626 .. option:: -Wno-long-long
4628 Default setting; overrides :option:`-Wlong-long`.
4630 .. option:: -Wvariadic-macros
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`.
4637 .. option:: -Wno-variadic-macros
4639 Default setting; overrides :option:`-Wvariadic-macros`.
4641 .. option:: -Wno-varargs
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.
4646 .. option:: -Wvarargs
4648 Default setting; overrides :option:`-Wno-varargs`.
4650 .. option:: -Wvector-operation-performance
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
4661 .. option:: -Wno-vector-operation-performance
4663 Default setting; overrides :option:`-Wvector-operation-performance`.
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.
4671 .. option:: -Wno-vla
4673 Default setting; overrides :option:`-Wvla`.
4675 .. option:: -Wvla-larger-than={byte-size}
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.
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
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).
4691 See also :option:`-Walloca-larger-than=byte-size`.
4693 .. option:: -Wno-vla-larger-than
4695 Disable :option:`-Wvla-larger-than=` warnings. The option is equivalent
4696 to :option:`-Wvla-larger-than=SIZE_MAX` or larger.
4698 .. option:: -Wvla-parameter
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`.
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.
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.
4719 void f (int n, int[n]);
4720 void f (int, int[]); // warning: argument 2 previously declared as a VLA
4727 f (sizeof a, a); // warning: access to a by f may be out of bounds
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.
4735 .. option:: -Wno-vla-parameter
4737 Default setting; overrides :option:`-Wvla-parameter`.
4739 .. option:: -Wvolatile-register-var
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
4746 .. option:: -Wno-volatile-register-var
4748 Default setting; overrides :option:`-Wvolatile-register-var`.
4750 .. option:: -Wxor-used-as-pow
4754 C, C++, Objective-C and Objective-C++ only
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.
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.
4764 This warning is enabled by default. It can be silenced by converting one
4765 of the operands to hexadecimal.
4767 .. option:: -Wno-xor-used-as-pow
4769 Default setting; overrides :option:`-Wxor-used-as-pow`.
4771 .. option:: -Wdisabled-optimization
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.
4780 .. option:: -Wno-disabled-optimization
4782 Default setting; overrides :option:`-Wdisabled-optimization`.
4784 .. option:: -Wpointer-sign
4788 C and Objective-C only
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`.
4795 .. option:: -Wno-pointer-sign
4797 Default setting; overrides :option:`-Wpointer-sign`.
4799 .. option:: -Wstack-protector
4801 This option is only active when :option:`-fstack-protector` is active. It
4802 warns about functions that are not protected against stack smashing.
4804 .. option:: -Wno-stack-protector
4806 Default setting; overrides :option:`-Wstack-protector`.
4808 .. option:: -Woverlength-strings
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.
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++.
4821 This option is implied by :option:`-Wpedantic`, and can be disabled with
4822 :option:`-Wno-overlength-strings`.
4824 .. option:: -Wno-overlength-strings
4826 Default setting; overrides :option:`-Woverlength-strings`.
4828 .. option:: -Wunsuffixed-float-constants
4832 C and Objective-C only
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.
4840 .. option:: -Wno-unsuffixed-float-constants
4842 Default setting; overrides :option:`-Wunsuffixed-float-constants`.
4844 .. option:: -Wno-lto-type-mismatch
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.
4850 .. option:: -Wlto-type-mismatch
4852 Default setting; overrides :option:`-Wno-lto-type-mismatch`.
4854 .. option:: -Wno-designated-init
4858 C and Objective-C only
4860 Suppress warnings when a positional initializer is used to initialize
4861 a structure that has been marked with the :type-attr:`designated_init`
4864 .. option:: -Wdesignated-init
4866 Default setting; overrides :option:`-Wno-designated-init`.