llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

-Wuninitialized inside lambda #46257

Open fekir opened 4 years ago

fekir commented 4 years ago
Bugzilla Link 46913
Version trunk
OS Linux
CC @DougGregor,@zygoloid

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; }

wheatman commented 1 year 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