Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable the highest warning level in GCC compiler(Boost is heavily used)

I just read a book which recommends enable the highest warning level in GCC. I just check the doc online, and found there are too much parameters. I want to enable the highest warning level, which parameter should I use?

And we use Boost heavily in our project.

like image 750
Yang Avatar asked Aug 06 '13 03:08

Yang


People also ask

How do I enable warnings in GCC?

The warning is made into an error by -pedantic-errors . Same as -Wimplicit-int and -Wimplicit-function-declaration . This warning is enabled by -Wall . -Wimplicit-fallthrough is the same as -Wimplicit-fallthrough=3 and -Wno-implicit-fallthrough is the same as -Wimplicit-fallthrough=0 .

Which GCC flag is used to enable all compiler warnings?

gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.

Which option of GCC inhibit all warning messages?

If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option. Inhibit all warning messages. Make all warnings into errors. Make the specified warning into an error.

Which option can be used to display compiler warnings?

The WarningLevel option specifies the warning level for the compiler to display.


1 Answers

Contrary to cl which has 4 levels, gcc only has a set of options that you can turn on or off.

As mentioned by others, the -Wall is the default, which turns on many warnings already. The -pedantic option adds a few more. And -Wextra yet another group...

But to really capture many warnings, you'll have to add many manually.

There is a set I like to use, although someone told me that some of those were contradictory, I find that list rather good for my development work:

-Werror -Wall -Wextra -pedantic -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option

Note that I make use of -Werror because otherwise you get warnings and tend to ignore them. With -Werror, no more ignoring anything! Write pristine code and your software is much more likely to work as expected.

like image 79
Alexis Wilke Avatar answered Oct 15 '22 18:10

Alexis Wilke