https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106864
Bug ID: 106864 Summary: Unexpected capture of "constexpr int" variable inside lambda Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: a.elovikov at gmail dot com Target Milestone: --- void bad() { constexpr int x = 1; auto Outer = [&]() { auto L = [=]() { for (int i = 0; i < x; ++i) { } }; static_assert(sizeof(L) == 1); // fails }; } void good() { constexpr int x = 1; auto L = [=]() { for (int i = 0; i < x; ++i) { } }; static_assert(sizeof(L) == 1); // passes } Not sure if that's a bug from the standard conformance point of view, but I'd expect the L not to capture constexpr variable in both cases. Sizeof is one in both cases with clang and (MSVC v19.latest + "/std:c++latest /c") on godbolt.