This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Understanding compiler warning options
- From: Martin Sebor <msebor at gmail dot com>
- To: Edward Diener <eldlistmailingz at tropicsoft dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 29 Sep 2015 20:57:01 -0600
- Subject: Re: Understanding compiler warning options
- Authentication-results: sourceware.org; auth=none
- References: <muf7j4$h4c$1 at ger dot gmane dot org>
On 09/29/2015 05:41 PM, Edward Diener wrote:
I am trying to understand how the compiler decides which warnings are
issued when compiling a translation unit.
What is the default warnings that are issued if no compiler warning
options is set on the command line ?
I don't know of a GCC interface to reliably determine this but GCC
itself decides this by parsing the c.opt files such as the generic
gcc/common.opt or gcc/c-family/c.opt
or the target-specific
gcc/config/rs6000/rs6000.opt
An example might be the -Wdiv-by-zero warning that's defined like
this:
Wdiv-by-zero
C ObjC C++ ObjC++ Var(warn_div_by_zero) Init(1) Warning
Warn about compile-time integer division by zero
You may be able to tell (probably less reliably) from the manual
by searching for warning options listed in the negative -Wno-xxx
form. For instance:
-Wno-endif-labels
Do not warn whenever an #else or an #endif are followed by text.
means the option is enabled by default. Other options may say
when (e.g., in what language) they're enabled by default.
If I set a general option, such as -w, -Wall, or -Wextra, do these get
overridden by more specific compiler options no matter where in the
command line they are encountered, or does the order of the compiler
warnings on the command line matter in such a case ? As a specific
practical example if the command line has "-Wno-unused-local-typedef
-Wall ..." does the "-Wno-unused-local-typedef" override the "-Wall"
option ?
Unfortunately, this is neither documented nor necessarily intuitive
(YMMV). IME, the best way to find out is by experimenting.
AFAICS, -w disables all warnings regardless of what follows on the
command line.
-Wno-xxx disables prior -Wxxx on the command line.
-Wxxx or -Wno-xxx overrides -Wall or -Wextra on the command line,
prior or subsequent.
IMO, it would be useful to document this. I'm sure patches would
be welcome.
Martin