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

boost, c++, compiler-construction, gcc, warnings

Solution

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.

Problem

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.

Original source