[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pragma GCC diagnostic

From: Manuel López-Ibáñez
Subject: Re: pragma GCC diagnostic
Date: Fri, 17 Oct 2008 14:26:24 +0200

2008/10/17 Bruno Haible <address@hidden>:
> "#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.

We want most warnings to be controlled by an option. This is easy to fix.

>  - 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.

These are known limitations of pragma diagnostics. They are not going
to be fixed for GCC 4.4.

However, in this particular case, there is an easy workaround:

int f (void) __attribute__ ((__warn_unused_result__));
void g (void) { int i; i = f (); }

This silences the warning and makes it obvious that you are doing
something fishy.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]