3

I used to select the default warning level in C++ programming. For example, in VS, the default warning level is Level3 (/W3) and No (/WX-) (don't treat warnings as errors).

I am wondering is it a good practice to choose highest warning level in C++ programming, e.g. EnableAllWarnings (/Wall) with Yes (/WX) (treat warnings as errors)?

Any advice will be much appreciated.

2 Answers2

8

The compilers are usually very good in spotting mistakes, therefore I always enable all possible warnings and errors (-Wall and -Wextra for gcc), and turn warnings into errors. This way nothing gets through.

Also, I try to write as standard compliant code as possible (-pedantic for gcc), meaning I try to avoid compiler extensions.

Sometimes it is not possible, because of an external library. Then you are forced to put required settings to make it compile. Unfortunately this usually goes with lots of warnings.

BЈовић
  • 14,049
4

Generally speaking, yes, it is a good idea to raise warnings to the highest level possible.

You may get some warnings that are overly picky or that just don't worry you in which case you can explicitly pragma them away in specific locations. At least then you are making a specific and explicit decision to ignore the warning.

Warnings as errors is more contentious in my experience. Some people think it is very important to have turned on. I personally keep this turned off to allow a little more flexibility while I am writing code, but then I trust myself not to ignore warnings, and certainly never commit code containing warnings. I have in the past however turned this on to catch programmers who were not quite as conscientious as they should have been.

Claude
  • 41