This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: yet another wrong warning


On Wed, Nov 01, 2000 at 11:04:28AM -0800, Ulrich Drepper wrote:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> $ cat v.c
> #define SWAP(x, y) ({ typeof(x) _tmp = x; x = y; y = _tmp; })
> int a;
> int b;
> void
> foo (void)
> {
>   SWAP (a, b);
> }
> $ gcc -c -Wall v.c
> v.c: In function `foo':
> v.c:9: warning: value computed is not used
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Which value isn't used?

The result of the expression "y = _tmp;" I think.  The ({...}) is one of
those expression compound statement GCC extension things, right?  The last
statement in the list is evaluated as the value of the whole thing; that
value never gets used.

If you write "int c = SWAP (a, b);" -- yes, it's silly -- I would bet the
warning goes away.  (Probably to be replaced by something about c never
being used.)


Phil

-- 
pedwards at disaster dot jaj dot com  |  pme at sources dot redhat dot com
devphil at several other less interesting addresses in various dot domains
The gods do not protect fools.  Fools are protected by more capable fools.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]