[cfe-dev] -Wunused-value gets triggered only when storing/using intermediate outputs

Nehal J Wani via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 30 11:03:11 PST 2019


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.

Another way to look at this problem is by first storing the intermediate
output and then trying to use it:
$ clang++ -E -c test.cpp -o test.ii -Wall -Wextra -Wunused-value -Werror
$ clang++ -c test.ii -o test.o -Wall -Wextra -Wunused-value -Werror
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.


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191230/7703c23a/attachment.html>


More information about the cfe-dev mailing list