31

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.

5
  • 1
    Hmm, gcc respects the suppression, g++ doesn't. Is -Wno-unknown-pragmas an option? Commented Oct 12, 2012 at 1:44
  • @DanielFischer I guess you mean as a command line parameter to the compiler? This would disable the warning also in my own code which I don't want. Commented Oct 12, 2012 at 6:25
  • 1
    Okay, understandable. Maybe you could try including these headers as system headers, as suggested here? Commented Oct 12, 2012 at 8:55
  • That would be a nice solution indeed and it would have been my first choice from beginning. But I'm working with Eclipse (automatically generated make files) and Eclipse does not seem to offer a way to mark an include directory as system include directory. So it always uses -I and not -isystem. Commented Oct 12, 2012 at 9:38
  • Could be related to this bug: gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 Commented Jun 22, 2016 at 12:03

1 Answer 1

31

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:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.