This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pragma GCC diagnostic
- From: Jim Meyering <jim at meyering dot net>
- To: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- Cc: "Bruno Haible" <bruno at clisp dot org>, "Paolo Bonzini" <bonzini at gnu dot org>, bug-gnulib at gnu dot org, gcc at gcc dot gnu dot org
- Date: Fri, 17 Oct 2008 21:20:11 +0200
- Subject: Re: pragma GCC diagnostic
- References: <8763nriv8w.fsf@rho.meyering.net> <48F8504A.1000500@gnu.org> <87abd3habz.fsf@rho.meyering.net> <200810171329.17618.bruno@clisp.org> <6c33472e0810170526x3800d4e5t99cdd0e6e69c9cd@mail.gmail.com>
"Manuel LÃpez-IbÃÃez" <lopezibanez@gmail.com> wrote:
> 2008/10/17 Bruno Haible <bruno@clisp.org>:
>> "#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
...
> 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.
Thanks, but I prefer to use the ignore_value function.
Adding a set-but-not-used variable might well provoke
a warning some day, if it doesn't already.