programing tip

MSVC -Wall의 표준 헤더에있는 수천 개의 경고는 무엇입니까?

itbloger 2020. 11. 25. 07:44
반응형

MSVC -Wall의 표준 헤더에있는 수천 개의 경고는 무엇입니까?


어떤 사람들은 -Wall을 사용하도록 조언하는 것처럼 보이지만 일부 포함이 포함 된 main.cpp 만있는 작은 테스트 프로젝트에서 수행했을 때 대부분의 표준 헤더 또는 Windows 헤더에 5800 개의 경고가 표시됩니다.

의도 된 동작입니까? 컴파일 경고를 없애려면 어떻게해야합니까?

읽기 재미를 위해 다음은 몇 가지입니다.

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/

Visual C ++ /Wall.NET 에서 기본적으로 비활성화 된 모든 경고를 활성화합니다 /W4. 아시다시피, 이러한 경고 중 많은 부분이 기본적으로 비활성화 된 이유가 있습니다. /W4Visual C ++ 에서 사용 하는 것이 가장 좋습니다 .

인텔 C ++도 이와 같습니다 (EDG 프런트 엔드를 사용하는 다른 컴파일러에 대해서는 잘 모릅니다). 으로 설정하면 /W5수많은 정보 메시지가 나옵니다. 개인적으로 가장 좋아하는 것은 스토리지 클래스 지정자가 선언의 시작 부분에 있지 않은 경우 경고하는 것입니다 (따라서 const static int진행되지 static const int않지만 괜찮습니다).


제어 할 수없는 시스템 헤더의 경고를 비활성화하려면 다음 구문을 사용하십시오.

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

특정 경고에 대해 더 선택적으로 :

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

이 답변은 다른 Stack Overflow 스레드에서 도용되었습니다. ( 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


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

What I (we) want to do is to control the compiler warning level for our code - we want to be able to play with the /W flag. In practice, as already pointed out, /W4 enables all generally useful warnings (and also some spurious...).

As the problem comes from the MSFT header files, I modify in a clean way the Microsoft-supplied header files. There are not so many changes to implement.

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

#pragma warning( disable : 4305)

before the offending line, followed by:

#pragma warning( default : 4305)

after the offending line. No side effect. Microsoft could have done it this way, probably.

참고 URL : https://stackoverflow.com/questions/4001736/whats-up-with-the-thousands-of-warnings-in-standard-headers-in-msvc-wall

반응형