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

后端 未结 6 596
既然无缘
既然无缘 2020-11-27 16:22

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 standar

6条回答
  •  青春惊慌失措
    2020-11-27 17:00

    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.

提交回复
热议问题