[cfe-dev] The Conditional Operator and Unused Results
Justin Bogner
mail at justinbogner.com
Sat Oct 2 13:51:36 PDT 2010
Chris Lattner <clattner at apple.com> writes:
> What is the real-world code you're seeing this on, and what diagnostic are you getting?
There are two cases in the code base I was compiling. The first is
setting up a threading domain, of which the relevent bits are simply:
#define _GNU_SOURCE
#include <sched.h>
extern cpu_set_t cpuMask;
void setCpuAffinity(const int cpu)
{
CPU_ZERO( &cpuMask );
CPU_SET( cpu, &cpuMask );
}
This gives me:
$ ./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:
for (...; ...; doNextIteration ? ++i : i)
This one's not so bad, as I can change it to:
for (...; ...; (void)(doNextIteration ? ++i : i))
More information about the cfe-dev
mailing list