I submitted [bug 8282], which is that statements like (x?y++:0) will
warn about an unused result for the 0. This idiom occurs in macros for
control flow, ie, in CPU_SET.
Currently, (x ? y : z) warns if either y or z would warn. Should this be
changed to warn only if both y and z would warn?
$ ./Debug+Asserts/bin/clang -fsyntax-only ~/tmp/cpuset.c
/home/bogner/tmp/cpuset.c:8:5: warning: expression result unused [-Wunused-value]
CPU_SET( cpu, &cpuMask );
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/bogner/tmp/cpuset.c:2:
/usr/include/sched.h:72:33: note: instantiated from:
# define CPU_SET(cpu, cpusetp) __CPU_SET_S (cpu, sizeof (cpu_set_t), cpusetp)
^
In file included from /home/bogner/tmp/cpuset.c:2:
In file included from /usr/include/sched.h:35:
/usr/include/bits/sched.h:145:9: note: instantiated from:
: 0; }))
^
1 warning generated.
This is the more serious case, because It's not easy to suppress
warnings from standard headers. The other case involved an iterator
foreach macro, which has something like:
I opened http://llvm.org/bugs/show_bug.cgi?id=8218 about this a few days
ago. GCC heuristic seems that the return value of an expression
statement not being used is just fine.
And like I say in the bug report it makes sense because expression
statements are usually used through a macro, that looks like a funcall,
and well, if clang doesn't warn if you don't catch the return value of a
function call, then it shouldn't warn if you don't catch the return
value of an expression statement.