xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/doc/cppwarnopts.texi (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1*4c3eb207Smrg@c Copyright (C) 1999-2020 Free Software Foundation, Inc.
23ad841b2Smrg@c This is part of the CPP and GCC manuals.
33ad841b2Smrg@c For copying conditions, see the file gcc.texi.
43ad841b2Smrg
53ad841b2Smrg@c ---------------------------------------------------------------------
63ad841b2Smrg@c Options affecting preprocessor warnings
73ad841b2Smrg@c ---------------------------------------------------------------------
83ad841b2Smrg
93ad841b2Smrg@c If this file is included with the flag ``cppmanual'' set, it is
103ad841b2Smrg@c formatted for inclusion in the CPP manual; otherwise the main GCC manual.
113ad841b2Smrg
123ad841b2Smrg@item -Wcomment
133ad841b2Smrg@itemx -Wcomments
143ad841b2Smrg@opindex Wcomment
153ad841b2Smrg@opindex Wcomments
163ad841b2SmrgWarn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
173ad841b2Smrgcomment, or whenever a backslash-newline appears in a @samp{//} comment.
183ad841b2SmrgThis warning is enabled by @option{-Wall}.
193ad841b2Smrg
203ad841b2Smrg@item -Wtrigraphs
213ad841b2Smrg@opindex Wtrigraphs
223ad841b2Smrg@anchor{Wtrigraphs}
233ad841b2SmrgWarn if any trigraphs are encountered that might change the meaning of
243ad841b2Smrgthe program.  Trigraphs within comments are not warned about,
253ad841b2Smrgexcept those that would form escaped newlines.
263ad841b2Smrg
273ad841b2SmrgThis option is implied by @option{-Wall}.  If @option{-Wall} is not
283ad841b2Smrggiven, this option is still enabled unless trigraphs are enabled.  To
293ad841b2Smrgget trigraph conversion without warnings, but get the other
303ad841b2Smrg@option{-Wall} warnings, use @samp{-trigraphs -Wall -Wno-trigraphs}.
313ad841b2Smrg
323ad841b2Smrg@item -Wundef
333ad841b2Smrg@opindex Wundef
343ad841b2Smrg@opindex Wno-undef
353ad841b2SmrgWarn if an undefined identifier is evaluated in an @code{#if} directive.
363ad841b2SmrgSuch identifiers are replaced with zero.
373ad841b2Smrg
383ad841b2Smrg@item -Wexpansion-to-defined
393ad841b2Smrg@opindex Wexpansion-to-defined
403ad841b2SmrgWarn whenever @samp{defined} is encountered in the expansion of a macro
413ad841b2Smrg(including the case where the macro is expanded by an @samp{#if} directive).
423ad841b2SmrgSuch usage is not portable.
433ad841b2SmrgThis warning is also enabled by @option{-Wpedantic} and @option{-Wextra}.
443ad841b2Smrg
453ad841b2Smrg@item -Wunused-macros
463ad841b2Smrg@opindex Wunused-macros
473ad841b2SmrgWarn about macros defined in the main file that are unused.  A macro
483ad841b2Smrgis @dfn{used} if it is expanded or tested for existence at least once.
493ad841b2SmrgThe preprocessor also warns if the macro has not been used at the
503ad841b2Smrgtime it is redefined or undefined.
513ad841b2Smrg
523ad841b2SmrgBuilt-in macros, macros defined on the command line, and macros
533ad841b2Smrgdefined in include files are not warned about.
543ad841b2Smrg
553ad841b2Smrg@emph{Note:} If a macro is actually used, but only used in skipped
563ad841b2Smrgconditional blocks, then the preprocessor reports it as unused.  To avoid the
573ad841b2Smrgwarning in such a case, you might improve the scope of the macro's
583ad841b2Smrgdefinition by, for example, moving it into the first skipped block.
593ad841b2SmrgAlternatively, you could provide a dummy use with something like:
603ad841b2Smrg
613ad841b2Smrg@smallexample
623ad841b2Smrg#if defined the_macro_causing_the_warning
633ad841b2Smrg#endif
643ad841b2Smrg@end smallexample
653ad841b2Smrg
663ad841b2Smrg@item -Wno-endif-labels
673ad841b2Smrg@opindex Wno-endif-labels
683ad841b2Smrg@opindex Wendif-labels
693ad841b2SmrgDo not warn whenever an @code{#else} or an @code{#endif} are followed by text.
703ad841b2SmrgThis sometimes happens in older programs with code of the form
713ad841b2Smrg
723ad841b2Smrg@smallexample
733ad841b2Smrg#if FOO
743ad841b2Smrg@dots{}
753ad841b2Smrg#else FOO
763ad841b2Smrg@dots{}
773ad841b2Smrg#endif FOO
783ad841b2Smrg@end smallexample
793ad841b2Smrg
803ad841b2Smrg@noindent
813ad841b2SmrgThe second and third @code{FOO} should be in comments.
823ad841b2SmrgThis warning is on by default.
83