Reputation: 348
In C/C++ code I try to port, a deprecated system header is included:
From the header:
#ifdef __GNUC__
#warning "this header is deprecated"
#endif
As we compile here with gcc -Wall -Werror
, compilation stops.
In the long run, replacing the use of deprecated functions is best, but for now I want to disable just this warning.
Compiling without -Werror
of course works, but as this is part of a completely automated build process, I prefer not to do that.
Including the header with #undef
ing __GNUC__
before and #define
ing it afterwards is a possibility, but I'm worried of the side effects inside the included header.
Is there a way to either disable #warning
or relax -Werror
just for one header?
Upvotes: 8
Views: 1407
Reputation: 7194
You can do this with a (GCC specific) diagnostic pragma
If you surround the include with the following it will disable any warnings caused by #warning
.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include "header.h"
#pragma GCC diagnostic pop
Note that if you change the ignored
to warning
in the above the compiler still prints the warnings - it just doesn't act on the -Werror
flag for them.
Upvotes: 9
Reputation: 12227
This disables precisely one type of warnings, the #warning directive, so I presume it's the safest solution to this problem:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-W#warnings"
#include <evilheader.h>
#pragma GCC diagnostic pop
(Edit: Sorry, turns out gcc is actually clang on my system, so may not work with your genuine gcc)
Upvotes: 2