How to disable GCC warnings for a few lines of code

后端 未结 9 773
我寻月下人不归
我寻月下人不归 2020-11-22 08:32

In Visual C++, it\'s possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for \"next line\",

9条回答
  •  难免孤独
    2020-11-22 09:03

    It appears this can be done. I'm unable to determine the version of GCC that it was added, but it was sometime before June 2010.

    Here's an example:

    #pragma GCC diagnostic error "-Wuninitialized"
        foo(a);         /* error is given for this one */
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wuninitialized"
        foo(b);         /* no diagnostic for this one */
    #pragma GCC diagnostic pop
        foo(c);         /* error is given for this one */
    #pragma GCC diagnostic pop
        foo(d);         /* depends on command line options */
    

提交回复
热议问题