Suppress -Wunknown-pragmas warning in GCC

安稳与你 提交于 2019-11-27 05:53:42

问题


I try to ignore warnings coming from some 3rd party header files like this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wreorder"

#include <some_3rd_party_header.h>

#pragma GCC diagnostic pop

This approach seems to work in general, but not for the unknown pragma warnings (I still get them).

Why does it work for other warnings but not for this one? Can anyone confirm this behaviour?

I'm using g++ (version 4.7.1) with -Wall and -std=c++0x under Debian.


回答1:


I've run into this annoyance, too. According to the GCC manpage -Wall turns on -Wunknown-pragmas for you, so just manually disable it using -Wno-unknown-pragmas after -Wall.

There is a GCC feature request to make this work using #pragma GCC diagnostic:

  • C++ preprocessor ignores #pragma GCC diagnostic


来源:https://stackoverflow.com/questions/12842306/suppress-wunknown-pragmas-warning-in-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!