Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ or gcc option to get warning message with warning id

By default gcc/g++ prints a warning message with the line number only. I am looking for the option by which g++ or gcc associates the build warning messages with the warning ids, so that the warning messages can be identified easily (without parsing). Also can there be any more option to get a more detailed warning message ? (Though I think each of the warning message is pretty much explanatory by itself, but just curious)

Thanks.

like image 916
mnshsnghl Avatar asked Oct 21 '08 05:10

mnshsnghl


People also ask

Which option of GCC inhibit all warning messages?

-Wno-coverage-invalid-line-number can be used to disable the warning or -Wno-error=coverage-invalid-line-number can be used to disable the error. Suppress warning messages emitted by #warning directives.

How do I enable warnings in GCC?

This warning is enabled by -Wall . Warn when a #pragma directive is encountered which is not understood by GCC. If this command line option is used, warnings will even be issued for unknown pragmas in system header files. This is not the case if the warnings were only enabled by the -Wall command line option.

Which option can be used to display compiler warnings?

You can use a #pragma warning directive to control the level of warning that's reported at compile time in specific source files. Warning pragma directives in source code are unaffected by the /w option.


1 Answers

In GCC 4.x there is an option "-fdiagnostics-show-option" which displays the option used to switch off the warning:

$ gcc -fdiagnostics-show-option foo.c -Wall -o foo
foo.c: In function ‘main’:
foo.c:3: warning: unused variable ‘x’ [-Wunused-variable]
foo.c:4: warning: control reaches end of non-void function

In case you need to parse the warning, this may simplify things (especially in the presence of localized error messages).

like image 146
JesperE Avatar answered Sep 30 '22 16:09

JesperE