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.

Robert Hegner
  • 9,014
  • 7
  • 62
  • 98
  • 1
    Hmm, gcc respects the suppression, g++ doesn't. Is `-Wno-unknown-pragmas` an option? – Daniel Fischer Oct 12 '12 at 01: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. – Robert Hegner Oct 12 '12 at 06:25
  • 1
    Okay, understandable. Maybe you could try including these headers as system headers, as suggested [here](http://stackoverflow.com/q/1867065/1011995)? – Daniel Fischer Oct 12 '12 at 08: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`. – Robert Hegner Oct 12 '12 at 09:38
  • Could be related to this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 – sigy Jun 22 '16 at 12:03

1 Answers1

30

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:

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
Nik Reiman
  • 39,067
  • 29
  • 104
  • 160