yet another wrong warning

Phil Edwards pedwards@disaster.jaj.com
Wed Nov 1 11:16:00 GMT 2000


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.


More information about the Gcc-bugs mailing list