[Bug c++/112546] New: -Wmaybe-uninitialized and -Wuninitialized does not detect usage of uninitilazed value in a lambda
federico at kircheis dot it
gcc-bugzilla@gcc.gnu.org
Wed Nov 15 13:05:49 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112546
Bug ID: 112546
Summary: -Wmaybe-uninitialized and -Wuninitialized does not
detect usage of uninitilazed value in a lambda
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico at kircheis dot it
Target Milestone: ---
I noticed the issue when comparing this three equivalent bar functions:
----
struct data{
int i;
};
data foo();
void bar(const data& d);
void bar1(){
data d = [&]{bar(d); return foo();}();
}
void bar2(){
data d = (bar(d), void(), foo());
}
void bar3(){
data d;
bar(d);
d = foo();
}
----
example on godbolt: https://godbolt.org/z/Wxj6rbKb9
With "-Wmaybe-uninitialized", GCC detects in bar2 and bar3 that d is possible
used inside bar without being initialized, but it fails to do so when using a
lambda.
In fact, I noticed that it fails to report (with "-Wuninitialized") even when
the value is used directly in the lambda:
----
void bar4(){
data d = [&]{ ++d.i; bar(d); return foo();}();
}
----
More information about the Gcc-bugs
mailing list