"#pragma GCC diagnostic" has a few limitations, which make it unusable to resolve warnings like this one:
Jim Meyering wrote in [1]: > $ cat in.c > int f (void) __attribute__ ((__warn_unused_result__)); > void g (void) { (void) f (); } > $ gcc -Werror -c in.c > cc1: warnings being treated as errors > in.c: In function 'g': > in.c:2: error: ignoring return value of 'f', declared with attribute > warn_unused_result It is a pity that "#pragma GCC diagnostic" [2] cannot be used to get rid of this warning, for three reasons: - gcc's warning is not triggered by a particular option. It's on by default. It's not clear what should by the second argument of "#pragma GCC diagnostic". An empty string does not work. - It would be needed to restore the previous setting after the line. But there's no #pragma GCC push-diagnostic/pop-diagnostic. - The restriction that the "#pragma GCC diagnostic" should not occur inside functions does not lead to maintainable code. We want to have the annotation to inhibit the warning to be just one line away from the code that triggers the warning. Bruno [1] http://lists.gnu.org/archive/html/bug-gnulib/2008-10/msg00278.html [2] http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html