[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pragma GCC diagnostic
From: |
Jim Meyering |
Subject: |
Re: pragma GCC diagnostic |
Date: |
Fri, 17 Oct 2008 21:26:45 +0200 |
Jim Meyering <address@hidden> wrote:
> "Manuel López-Ibáñez" <address@hidden> wrote:
>> 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
> ...
>> 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.
For those not following the original bug-gnulib thread,
http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/15221
this is the function:
static inline void
ignore_value (int i __attribute__ ((__unused__)))
{
/* empty */
}
Re: [PATCH] ignore-value: new module, Jim Meyering, 2008/10/17
Re: [PATCH] ignore-value: new module, Bruno Haible, 2008/10/17