[cfe-dev] How can I use the result of a void expression? :p
Keith Bauer
onesadcookie at gmail.com
Mon Aug 27 03:38:27 PDT 2007
> Yep, that's a bug, but not because ?: has side effects. It is
> because that warning should never be emitted for a void expression,
> patch here:
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-
> Mon-20070820/001680.html
I think my patch is still necessary:
int r(void);
void foo(int f)
{
f ? r() : r() + r();
}
imac:Desktop keith$ gcc -fsyntax-only -Wall -Wextra side-effect-test.c
imac:Desktop keith$ clang -fsyntax-only side-effect-test.c
side-effect-test.c:4:5: warning: expression result unused
f ? r() : r() + r();
^~~~~~~~~~~~~~~~~~~
1 diagnostic generated.
( replacing + with , makes more sense but then my patch still isn't
sufficient ;) )
Maybe the warning should never be emitted for expressions returning
void, but that's more of a consequence that a void expression should
always have a side effect than the underlying reason not to emit the
warning...
-Keith
More information about the cfe-dev
mailing list