-Wunused-value gets triggered only when storing/using intermediate outputs

Dear Clang Devs,

Consider the following code snippet:

#include <sched.h>
void whatever() {
cpu_set_t d, s1, s2;
CPU_AND(&d, &s1, &s2);

On compiling normally, I see no warnings being emitted:
$ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror

However, if I ask Clang to save the temporary files:
$ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror --save-temps
test.cpp:5:308: error: expression result unused [-Werror,-Wunused-value]
(extension ({ cpu_set_t *__dest = (&d); __const __cpu_mask *__arr1 = (&s1)->__bits; __const __cpu_mask *__arr2 = (&s2)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] & __arr2[__i]; __dest; }));
1 error generated.

Some of Clang's warnings, such as this one, are disabled if the code comes
from a macro expansion. This is why you see the warning only if you first
expand the code.

If your concern is just related to distributed compiling, either build
without -Werror, or use icecc/icecream, which generally distributes the
builds without preprocessing first.

You can also use -frewrite-includes to avoid a full preprocessing (rather than -E). I’m not sure if this necessarily gets you exact warning reproducibility, but closer.

I was suggested at #llvm to send a ping! :slight_smile:


> Questions:
> - Is this report of unused value legit? GCC doesn't warn anything on the
> same snippet. - Is this behavior expected? Why does the warning throw up
> only when the end user wants to do anything with the intermediate
> outputs? I ended up here because this was failing my project when I was
> trying to use distcc.
> Cheers!
> Nehal J Wani

I was suggested at LLVM Project to send a ping! :slight_smile:

I already answered your questions on Jan 5th. If you missed the mail, check
the archives.