What happens to thousands of warnings in standard headers in MSVC-Wall?

Some people seem to advise you to use -Wall, but when I did this in a small test project that only has main.cpp with some of them, I get 5800 warnings, most of which are in standard headers or window headers.

Is this intentional behavior? How do I make a free compilation notice?

Here are just a few of the few to read:

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/ 
+58
c ++ compiler-warnings visual-c ++
Oct 22 '10 at 23:55
source share
6 answers

Visual C ++ /Wall includes all warnings that are disabled by default in /W4 . As you know, there is a good reason why many of these warnings are turned off by default (thanks, compiler, for saying that you added indentation, I really appreciate it!). It is probably best to use /W4 in Visual C ++.

Intel C ++ is similar to this too (I don't know about other compilers that use the EDG interface). If you install it on /W5 , it spews a ton of informational messages. My personal favorite is that it warns you if the storage class specifier is not at the beginning of the declaration (therefore, const static int does not, but static const int is ok).

+37
Oct 23 '10 at 0:02
source share

To disable warnings from system headers that you have no control over, simply 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 has been stolen from another thread: ( https://stackoverflow.com/a/167478/ ).

I completely agree with the comments of "edA-qa mort-ora-y". I want to see all warnings in my code, including important things like C4265 (DTOR is not virtual). Although C4265 is at warning level 3, Microsoft thought it turned 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 them and suppress noise from external headers, this page gives excellent advice, and I think that fully answers the original question that started this topic:

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

Essentially, he advises creating a β€œglobal” include file with the appropriate #pragmas to suppress warnings that you are not interested in (maybe C4820 indented), to protect against external headers, as described above, then compile with / Wall. This is part of the job, but worth it. With GCC, this will simply be a matter of using -isystem. Microsoft Development: Pay Attention! VS is a smart product, but sometimes it's just stupid.

+26
May 18 '13 at 19:20
source share

I know that it is already late, but I believe that I have a way to use / Wall for your own files, but I should not see noise from Microsoft or other "external" headers. It is assumed that you use precompiled headers through stdafx. h.

  • For the project, set the warning level to / Wall (maximum warnings)
  • Set the warning level to / W 4 for the stdafx.cpp file (many warnings are enabled, but MS headers pass silently).
  • For the project, in the section "Disable special warnings" add 4652

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

It is tiring to do this for every new project, but not as bad as the many individual prohibitions of #pragma warning ().

+8
Sep 26 '13 at 16:55
source share

For MSVC, use /W4 .

+6
Oct 22 '10 at 23:57
source share

in MSVC 2010

Options

Connection Properties

C / c ++

Additionally

Disable special alerts

set a value similar to 4820; 4996; 4514; 4710, to explain, disable warnings that you consider to be irrelevant. At this point, you can -WALL not worry

+2
Aug 27 '13 at 15:49
source share

I have the same initial problem when compiling various software stacks with VC6 and Microsoft Platform SDK (e.g. in BaseTsd.h).

What I (we) want to do is control the compiler warning level for our code - we want to be able to play with the / W flag. In practice, as already mentioned, / W 4 resolves all public warnings (as well as some false warnings ...).

Since the problem arises from the MSFT header files, I am modifying the header files supplied by Microsoft in a clean way. There are not many changes to implement.

If the compiler complains about warning C4305, in the source file I insert:

 #pragma warning( disable : 4305) 

to the line of violation followed by:

 #pragma warning( default : 4305) 

after the line of violation. No side effect. Maybe Microsoft did it, maybe.

+1
Aug 27 '13 at 15:23
source share



All Articles