Open fekir opened 4 years ago
confirming that this is still the case in post 17 trunk(68e94f1f27b658183c3ebbce4aaadc437d0cee3a) https://godbolt.org/z/1M9d4Ko7q
code
int main() {
int i = [&](){return i;}();
return i;
}
gcc warning
<source>: In function 'int main()':
<source>:2:9: warning: 'i' is used uninitialized [-Wuninitialized]
2 | int i = [&](){return i;}();
| ^
Compiler returned: 0
Extended Description
I've a bug that GCC was able to avoid thanks to "-Wuninitialized -O1", but that clang fails to diagnose.
The reduced test-case is
int main() { int i = [&](){return i;}(); return i; }
I've tried compiling with "-Weverything -Wno-c++98-compat -O2" and other optimizations level, without any luck.
Notice that
int main() { int i = i; return i; }
gets diagnosed correctly with "warning: variable 'i' is uninitialized when used within its own initialization [-Wuninitialized]".
Another example where clang does not emit any diagnostic but GCC does:
int main() { int i; [&](){i++;}(); return i; }