[cfe-dev] How can I use the result of a void expression? :p
Neil Booth
neil at daikokuya.co.uk
Mon Aug 27 06:28:38 PDT 2007
Keith Bauer wrote:-
> > 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...
Though it's most likely a separate issue, for the above testcase,
f ? r() : r() + r();
~~~ ^ ~~~
"unused operation" would be more appropriate I suspect.
Neil.
More information about the cfe-dev
mailing list