Is there a way to disable all warnings with a pragma?

前端 未结 4 1098
遇见更好的自我
遇见更好的自我 2020-12-14 05:44

I\'ve started a new project and have decided to make sure it builds cleanly with the /Wall option enabled. The only problem is not all 3rd party libraries (like boost) compi

4条回答
  •  悲哀的现实
    2020-12-14 06:23

    Using the technique described in the Assaf Lavie's answer it is possible to create helper macros:

    #define DISABLE_ALL_WARNINGS_BEGIN \
        __pragma(warning(push, 0))
    
    #define DISABLE_ALL_WARNINGS_END \
        __pragma(warning(pop))
    

    They can be used in the following way (online demo):

    DISABLE_ALL_WARNINGS_BEGIN
    void foo(int a)
    {
        // this function should generate the following warning
        // "warning C4100: 'a': unreferenced formal parameter"
        // unless it is wrapped inside "DISABLE_ALL_WARNINGS" section
    }
    DISABLE_ALL_WARNINGS_END
    

提交回复
热议问题