[cfe-dev] How can I use the result of a void expression? :p
Chris Lattner
clattner at apple.com
Sun Aug 26 10:33:48 PDT 2007
On Aug 26, 2007, at 4:39 AM, Keith Bauer wrote:
> imac:Desktop keith$ cat > conditionalvoid.c
> extern void foo();
> extern void bar();
> void baz(int c) {
> c ? foo() : bar();
> }
> imac:Desktop keith$ gcc -fsyntax-only -Wall -Wextra conditionalvoid.c
> imac:Desktop keith$ clang -fsyntax-only conditionalvoid.c
> conditionalvoid.c:4:3: warning: expression result unused
> c ? foo() : bar();
> ^~~~~~~~~~~~~~~~~
> 1 diagnostic generated.
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
> ( ?: on void is perfectly legal according to C99 6.5.15 )
Sure. Warnings are for code that is legal but questionable :)
Thanks,
-Chris
More information about the cfe-dev
mailing list