This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How do I disable warnings across gcc versions?
- From: Andy Lutomirski <luto at amacapital dot net>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 14 May 2012 15:26:38 -0700
- Subject: How do I disable warnings across gcc versions?
This code warns (incorrectly, but that's a whole separate issue):
double foo(double a, double b)
{
bool option1_ok, option2_ok;
double option1, option2;
if (a == 0) {
option1_ok = false;
} else {
option1 = b;
option1_ok = true;
}
if (a == 1) {
option2_ok = false;
} else {
option2 = b;
option2_ok = true;
}
if (option1_ok) return option1;
if (option2_ok) return option2;
return 7;
}
Unfortunately, the bogus warning is -Wuninitialized in gcc 4.6 and
-Wmaybe-uninitialized in gcc 4.7. The obvious way to silence the
warning is to wrap it in:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
...
#pragma GCC diagnostic pop
It silences the original warning, but now gcc 4.6 says:
warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
This seems to defeat the purpose, and adding
#pragma GCC diagnostic ignored "-Wpragmas"
is a little gross. How am I supposed to do this?
Thanks,
Andy