none
#pragma warning(push, 0) can't disable /Wall warning on Visual Studio 2017 RRS feed

  • Question

  • Hi, all.

    I found a problem that seems a compiler bug but I can't make sure.


    Step to reproduce:

    1. Create new empty project on Visual Studio 2017 Ver 15.2 (26430.6)
    2. Set /Wall
    3. Add new empy source file
    4. copy & paste below code.
    #pragma warning (push, 0)
    #include <iostream>
    #pragma warning (pop)
    
    int main()
    {
    	return 0;
    }

    Actual behaivor: There are many many warnings (e.g. C4365, 4820, 4626, 5027...etc) in system header (e.g. xmemory0, xlocale, system_error...etc).

    Expected behaivor: All warnings are suppressed by "#pragma warning (push, 0)"

    Note that this problem can't be reproduced on Visual Studio 2015 Ver 14.0.23107.0 D14REL.

    Could you give me some your opinions or point me a my fault?


    Friday, May 26, 2017 5:38 AM

All replies

  • Hi aokomoriuta,

    thanks for posting here.

    >>Actual behaivor: There are many many warnings (e.g. C4365, 4820, 4626, 5027...etc) in system header (e.g. xmemory0, xlocale, system_error...etc).

    Expected behaivor: All warnings are suppressed by "#pragma warning (push, 0)"

    Note that this problem can't be reproduced on Visual Studio 2015 Ver 14.0.23107.0 D14REL.

    Could you give me some your opinions or point me a my fault?

    As tested with your steps in my vs2017, I couldn't reproduce your problem.

    And the warning came out from your project make me confused. There may be something wrong with your vs. Please repair your vs or update it to the latest version and try again.

    Best Regards,

    Sera Yu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Baron Bi Wednesday, May 31, 2017 6:11 AM
    • Unproposed as answer by aokomoriuta Thursday, July 6, 2017 4:53 PM
    Friday, May 26, 2017 7:51 AM
  • Hi aokomoriuta,

    Has your case been solved?

    If it has, pleas help to mark answers. If not, just feel free to contact us.

    Your understanding and cooperation will be grateful.

    Best Regards,
    Sera Yu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Baron Bi Monday, June 5, 2017 7:21 AM
    Monday, June 5, 2017 7:20 AM
  • Thank you for your comment and sorry for my late response.

    I will try your answer next week and report the result ASAP.

    Monday, June 26, 2017 2:35 AM
  • I get this problem myself in the latest versions of Visual Studio 2017. Both 15.2 and 15.3 preview. This requires that the EnableAllWarnings (/Wall) option be set in the compiler options.


    This is a signature Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Tuesday, June 27, 2017 5:06 PM
  • @Darran Rowe Thanks for confirmation.

    Yes, I updated my VS 2017 and tried but the problem occurred. Sera Yu might forget set /Wall therefore he/she couldn't get the error.

    I need other helps to solve this problem.

    Thanks.


    Thursday, July 6, 2017 4:53 PM
  • Problem persists on latest VS2017 version 15.9.15. #pragma warning(push,0) doesn't disable all warnings with or without Wall W4 or w/e else enabled.
    Friday, September 20, 2019 8:11 AM
  • Problem persists on latest VS2017 version 15.9.15. #pragma warning(push,0) doesn't disable all warnings with or without Wall W4 or w/e else enabled.
    How about updating to the actual VS2019 Version? Does the problem still exist there too?
    Friday, September 20, 2019 8:57 AM
  • This is so by design.

    If you guys wan't to compile with /Wall and suppress warnings from standard headers you need to disable each warning separately before header inclusion like in the bellow code sample:

    #pragma warning (push) // first push

    #pragma warning (disable : 4061)

    #pragma warning (disable : 4191)

    #pragma warning (disable : 4365)

    #pragma warning (disable : 4371)

    // and the list goes on... add pragmas as needed

    // now include standard headers

    #include <iostream>

    #include <string>

    #include <thread>

    // add header as needed before pragma pop...

    #pragma warning (pop) // finally pop

    // your code and your own headers go here, after pragma pop

    #include "my header1"

    #include "myHeader2"

    int main()

    {     

     // my super code with /Wall goes here

    }


    Please note that if you want to avoid doing this for every source file in your project just make a precompiled header and put these pragmas and standard headers into precompiled header (that is everything between push 

    and pop inclusive!), then include precompiled header into each source file before any other headers.hYou ca go one step further if you wish to autmate this, make a "pragmas.h" header and use it as template for all you precompiled headers across

    different projects. that is you include pragmas.h into precompiled header first, and then pop at the end of precompiled header (after standard headers) with pragma pop.

    this will raise new warning because pop is used in different file. just surround it with pragma disable and pragma enable that specific warning.



    • Edited by metablaster Wednesday, October 9, 2019 12:58 AM
    Tuesday, October 8, 2019 11:39 PM