-
Bug
-
Resolution: Unresolved
-
Medium
-
Code Generation Tools
-
CODEGEN-4002
-
Undefined behavior on lambda capturing constexpr by reference. The C++ standard provides the following example:
struct S
{ int n; };
auto f() {
S x
;
constexpr S y
;
return [&](bool b)
;
}
auto g = f();
int m = g(false); // undefined behavior due to access of x.n outside its lifetime
int n = g(true); // OK, does not access y.n
gcc-7.2 replaces the reference to y.n with the constant 2, avoiding undefined behavior.