Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's up with the thousands of warnings in standard headers in MSVC -Wall?

The Visual C++ /Wall enables all of the warnings that are disabled by default at /W4. As you've found out, there is a good reason why a lot of those warnings are disabled by default (thanks, compiler, for telling me you've added padding; I really appreciate it!). It's probably best just to use /W4 on Visual C++.

Intel C++ is like this too (I don't know about other compilers that utilize the EDG frontend). If you set it at /W5, it spews out tons of informational messages. My personal favorite is that it warns you if the storage class specifier isn't at the beginning of a declaration (so, const static int is no go, but static const int is fine).


To disable warnings from system headers over which you have no control just use this construct:

#pragma warning(push, 0)       
//Some includes with unfixable warnings
#pragma warning(pop)

or more selectively for specific warnings:

#pragma warning( push )
#pragma warning( disable : 4081)
#pragma warning( disable : 4706 )
// system header includes 
#pragma warning( pop )

This answer was purloined from another Stack Overflow thread: (https://stackoverflow.com/questions/2541984/how-to-suppress-warnings-in-external-headers-in-visual-c).

I fully agree with the comments made by "edA-qa mort-ora-y". I want to see all warnings in my code, including important stuff like C4265 (DTOR not virtual). Although C4265 is at warning level 3, Microsoft in their wisdom have switched it off by default and you need /Wall to get it. See this page for more information about which warnings are hidden:

http://msdn.microsoft.com/en-GB/library/23k5d385(v=vs.80).aspx

To see these and to suppress the noise from the external headers, this page gives great advice, and I think fully answers the original question which started this thread:

http://blogs.msdn.com/b/vcblog/archive/2010/12/14/off-by-default-compiler-warnings-in-visual-c.aspx

Basically it advises to create a 'global' include file with the appropriate #pragmas to suppress the warnings you don't care about (maybe C4820 the padding one), to guard against external headers in the manner described above, then the compile with /Wall. That's a piece of work, but worth it. Under GCC it would just be a question of using -isystem. Microsoft development: take note! VS is a smart product but it's really dumb sometimes with the simple stuff.


I know that this is late in the game but I believe I have a way to use /Wall for your own files but not have to see the noise from the Microsoft or other "external" headers. This assumes you are using precompiled headers via stdafx.h.

  1. For the project, set the warning level to /Wall (maximum warnings)
  2. For the file stdafx.cpp, set the warning level to /W4 (lots of warnings enabled but MS headers pass silently)
  3. For the project, under Disable Specific Warnings, add 4652

The first two seem obvious. But when stdafx.h is included in your own files, the warning levels do not match and warning C4652 is issued. Which defeats the whole exercise. But now that message is also suppressed.

It is kinda tedious to do this for each new project but not as bad as lots of individual #pragma warning() suppressions.


For MSVC use /W4.


in MSVC 2010

Options

Coniguration Properties

C/C++

Advanced

Disable Specific Warnings

set a value like 4820;4996;4514;4710 to explicity disable the warnings that you consider unimportant. At that point you can -WALL without concern