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

Some people seem to advise you use -Wall, but when I did it on a small test project which just has a main.cpp with some includes, I get 5800 warnings most of them in standard headers or in windows headers.

Is that intended behaviour? How do I go about making my compilation warning free?

Here are just a few for some reading fun:

1>c:\program files\microsoft visual studio 10.0\vc\include\stdint.h(105): warning C4668: '_INTPTR' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(109): warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data member '_wfinddata64i32_t::attrib'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(114): warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data member '_wfinddata64i32_t::name'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(118): warning C4820: '_wfinddata64_t' : '4' bytes padding added after data member '_wfinddata64_t::attrib'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(488): warning C4820: '_stat32' : '2' bytes padding added after data member '_stat32::st_gid'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(504): warning C4820: 'stat' : '2' bytes padding added after data member 'stat::st_gid'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(520): warning C4820: '_stat32i64' : '2' bytes padding added after data member '_stat32i64::st_gid'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(521): warning C4820: '_stat32i64' : '4' bytes padding added after data member '_stat32i64::st_rdev'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(525): warning C4820: '_stat32i64' : '4' bytes padding added after data member '_stat32i64::st_ctime'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(534): warning C4820: '_stat64i32' : '2' bytes padding added after data member '_stat64i32::st_gid'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(548): warning C4820: '_stat64' : '2' bytes padding added after data member '_stat64::st_gid'
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(549): warning C4820: '_stat64' : '4' bytes padding added after data member '_stat64::st_rdev'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdbg.h(1078): warning C4986: 'operator new[]': exception specification does not match previous declaration
1>          c:\program files\microsoft visual studio 10.0\vc\include\new(79) : see declaration of 'operator new[]'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdbg.h(1095): warning C4986: 'operator delete[]': exception specification does not match previous declaration
1>          c:\program files\microsoft visual studio 10.0\vc\include\new(77) : see declaration of 'operator delete[]'
1>c:\program files\microsoft visual studio 10.0\vc\include\typeinfo(76): warning C4820: 'type_info' : '3' bytes padding added after data member 'type_info::_M_d_name'
1>c:\program files\microsoft sdks\windows\v7.0a\include\basetsd.h(114): warning C4668: '__midl' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8154): warning C4820: '_SECURITY_QUALITY_OF_SERVICE' : '2' bytes padding added after data member '_SECURITY_QUALITY_OF_SERVICE::EffectiveOnly'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8165): warning C4820: '_SE_IMPERSONATION_STATE' : '2' bytes padding added after data member '_SE_IMPERSONATION_STATE::EffectiveOnly'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8334): warning C4820: '_QUOTA_LIMITS' : '4' bytes padding added after data member '_QUOTA_LIMITS::PagefileLimit'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8357): warning C4820: '_QUOTA_LIMITS_EX' : '4' bytes padding added after data member '_QUOTA_LIMITS_EX::PagefileLimit'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8405): warning C4820: '_JOBOBJECT_BASIC_LIMIT_INFORMATION' : '4' bytes padding added after data member '_JOBOBJECT_BASIC_LIMIT_INFORMATION::SchedulingClass'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(8984): warning C4820: '_FILE_NOTIFY_INFORMATION' : '2' bytes padding added after data member '_FILE_NOTIFY_INFORMATION::FileName'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(9012): warning C4820: '_REPARSE_GUID_DATA_BUFFER' : '3' bytes padding added after data member '_REPARSE_GUID_DATA_BUFFER::GenericReparseBuffer'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(10131): warning C4820: '<unnamed-tag>' : '3' bytes padding added after data member '<unnamed-tag>::Data'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(10241): warning C4820: '<unnamed-tag>' : '4' bytes padding added after data member '<unnamed-tag>::DecreaseTime'
1>c:\program files\microsoft sdks\windows\v7.0a\include\winnt.h(10262): warning C4820: '<unnamed-tag>' : '4' bytes padding added after data member '<unnamed-tag>::TimerInterval' 
1>c:\program files\microsoft sdks\windows\v7.0a\include\wincrypt.h(1440): warning C4668: 'NTDDI_WINLH' is not defined as a preprocessor macro, replacing with '0' for '#if/

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.