What compiler warning level do you recommend for different C/C++ compilers?
gcc and g++ will let you get away with a lot on the default level. I find the best warning level for me is '-Wall'. And I always try to remove fix the code for the warnings it generates. (Even the silly ones about using parenthesis for logical precedence rules or to say I really mean 'if (x = y)')
What are your favorite levels for the different compilers, such as Sun CC, aCC (HPUX ?), Visual Studio, intel?
Edit:
I just wanted to point out that I don't use "-Werror" (but I do understand it's utility) on gcc/g++ because, I use:
#warning "this is a note to myself"
in a few places in my code. Do all the compilers understand the #warning macro?
On GCC, for preference I use
-Wall -Wextra -Wwrite-strings -Werror
, and also specify a standard withstd=
. Which standard depends on the project: principally on how portable it needs to be.The reason I use
-Werror
is that warnings are unacceptable (to me) even if they don't represent a real bug. I'd rather work around whatever caused the warning, than have to ignore warnings every single time I compile for the rest of my life. Once you allow warnings in the compile, it's just too easy to miss one that wasn't there last time.Of course when dealing with third-party code, sometimes you can't get rid of the warnings. Then I'd decide on a case-by-case basis whether to relax the
-W
options, remove-Werror
and write a script to check that only expect warnings occur, or maybe modify the third-party code (either to "fix" the warning or to disable it with pragmas if possible).In Visual C I use /w3. I find w4 throws up too much noise (lots of it from the MS libraries) to go through on every build. The extra warnings are very minor and haven't been a cause of a bug so far.
I also like check all possible warnings that give compiler in my project. Unfortunately answer about Intel C++ compiler was not very informative for me (link is dead). I made my own research.
Because i use Qt 5 and qmake i have predefined warning level -w1. Can't do nothing with that. But this is not all and ICC has more keys:
More about all keys.
Also i want to add that, unlike GCC, ICC produces several warnings for one key, for example key -Weffc++. In case you want only see several warnings from all list use key -wd.
I disable: -wd1418,2012,2015,2017,2022,2013. And warnings -wd1572,873,2259,2261 was disabled in qmake by default.
I use PCH and have found very annoying to see in Qt Creator messages about using PCH file like error. To disable, use -Wno-pch-messages.
For disabling warning in code i use:
I like -Wall and strict prototypes as well as implicit function definitions. Errors on those can be very useful. There's also -Wextra which will pick up all kinds of things like things you intended to be conditionals but accidentally wrote as statements:
On Unix-like systems you have to obey the user's ENV preferences .. so what they see and report might be entirely different than what you need :)
I'm also a type punning fiend, so I tend to set -Fno-strict-aliasing as well, unless the user wants it. Safe memory management in classic C is hard to accomplish otherwise.
I do all development with Warning as Errors turned on.
Since I still develop in VC6 I have a lot of #pragma's in my code (4786 mainly).
There's a nice list of options for GCC here: http://mces.blogspot.com/2008/12/year-end-cleaning-ie-on-warning-options.htm. -Wall does not enable all the possible warnings, and some have to be enabled explicitely.