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.
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 .
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
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.
The WarningLevel option specifies the warning level for the compiler to display.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With