Consider the C compilation unit:
int Y, Z;
void f(int n) {
long u[n];
Y = sizeof *(Z=1, &u);
}
Clang warns that the side-effect “Z=1” will have no effect because it's an unevaluated context, but actually, u is a VLA, and in this case side-effects happen. Note that the code generated by Clang is correct, it is only the warning that should not be emitted:
:5:14: warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression] Y = sizeof *(Z=1, &u); ^ 1 warning generated. Compiler returned: 0
Generated code with -O:
f: # @f
movl $1, Z(%rip)
shll $3, %edi
movl %edi, Y(%rip)
retq
Compiler Explorer link: https://gcc.godbolt.org/z/PG9cd9
The relevant C17 clause: https://cigix.me/c17#6.5.3.4.p2
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4