<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106867>106867</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] -Wunused-value does not warn about `literal;` if the literal is expanded from macro defined in system header
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sleeptightAnsiC
</td>
</tr>
</table>
<pre>
Hi,
given following C code:
```C
#include <stdbool.h>
int main (void)
{
true;
return 0;
}
```
```
$ gcc -Wunused-value main.c
$ clang -Wunused-value main.c
$ icx -Wunused-value main.c
```
I would expect that `-Wunused-value` would warn about `true;` statement
but it does not - not in GCC 14.2, nor in Clang 18.1, nor in Intel Compiler 2024.1.0
not unlsess I specify `-Wsystem-header`
However,
this functionality was working as expected back in GCC 3.4.6 and Clang 3.0.0
(regression / something has changed? see gobolt link down below)
and recent C++ front-ends DO catch this unlike C front-ends:
```
$ g++ -Wunused-value main.c
main.c: In function ‘int main()’:
main.c:4:9: warning: statement has no effect [-Wunused-value]
4 | true;
| ^
$ clang++ -Wunused-value main.c
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
main.c:4:5: warning: expression result unused [-Wunused-value]
4 | true;
| ^~~~
```
MSVC 19.40 also catches this with C11 Wall flags:
```
> cl /Wall /nologo /std:c11 main.c
main.c
main.c(4): warning C4555: result of expression not used
```
I've checked everything from GCC bugzilla's meta bug about `-Wunused` warnings and found nothing about it.
I also checked issues in LLVM github repo with the same result - nothing found.
I'm a bit concerned that since so many C compilers give the same result, this might be some kind of "agreed between everyone" behavior, but it looks like a bug so I'm reporting it as a bug :)
If it's not-a-bug, then PLEASE, give some rationale on this topic.
If this an actual bug then I can also send it further to GCC.
References:
https://godbolt.org/z/joK6348rE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77299
https://stackoverflow.com/questions/78935304/why-wunused-value-does-not-catch-a-statement-true/78935413#78935413
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVsGO47gR_Rr6UrAgUZJlH3zoVtvZRmaRIAvsHgOKLElcU6RDUvb0HubbA1Ky7DE6M5cAhkyVisWqx1ePZM7JTiPuSflKyrcVG31v7N4pxLOXXe9ftJP1qjHiY_-LJLQm6RtJX6ZnJy-ooTVKmavUHdTAjUCSvzw6kU06_W5TaS41V6NAIHntvGiMUUlP8sP0XWoPA5MaCN1ejBSE7uaJ1es0AADwdkSSPxgs-tFqSBcjqd6eEvj8lRbQcQ7rP0Y9OhTrC1MjxgwSfnfhiunuZ06Sf_2hy9PK8fkOVzMqAfj1jNyD75kHskm_D0M26ex2ZVYDa8wYvW4obFJwnnkcUPspbDN6kB6EQQfaeFjHp9Twt7qGrEgooTVoY4OpjrVl2yR7ML5rjwpqM5ylQgs0pUWSJXPqIdaolUPn4B3cGblsP6a03YfzOKx7ZALtU62_mCte0C4s8r100I6ae2k0U9J_wJU5uBp7CnRibkYFBTSMn27p50mRbIBpMWeeJ2my7ObWYmfROWkCg47gzIC-D-F65oD3THcoSH4EhwidaYzyoKQ-gTBXDQ0qc10YF5awyFF7qAl9JfQVWmu0X6MWDt7-AZx53kMsY9RKnhDqB4__1QgPxJuj_oA08zh_gXe9YAXkQMk2JbvtrVsI3Ya0Z_NuWXqZXpD8JZgjg6TuwnDhTMRGG8C2DSQk5esT_8q3e6cVQKoaPm1CWD7FcXl4aqCfl_vg9pSst8h82EdCK05oBVKfRx9IMhniFFrBtUcdWT0vNgRJovW0Sw327CIDwx0IPFvkLLArFnx_X8r9Dr3yKSH8er4RzaIbVWiJUNX_Az5SHr59-_YD2fj1t99ryHZJkQJTzkxMRDdVeZW-hzrL4A-mFLSKdT_jYn4ArkK_xBmEHrVRpjNh5Lwg-QvPss9o-Tim2yJQ8A4S1EVZRtRmfEz7CFoUEYfiR-JIaHVB4D3yEwoI4vExNXNrzRDFoBm7v6RSjNDKwYCeBct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