https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86147
Bug ID: 86147 Summary: Lambda is capturing a non-ODR-used constexpr Product: gcc Version: 8.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: julian.panetta at gmail dot com Target Milestone: --- Minimal example: #include<array> struct A { static constexpr size_t value = 0; }; template<class C> void foo() { constexpr size_t N = C::value; auto f = [&]{ std::array<int, N> a; }; }; int main() { foo<A>(); return 0; } On gcc 8.0.1 and 8.1.1 (built from the latest revision on SVN), this code produces an error: error: use of ‘this’ in a constant expression auto f = [&]{ std::array<int, N> a; }; ^ Apparently N is captured despite it not being ODR-used, leading to the error. The error is not reported on gcc 7, and it strangely disappears if C::value is replaced with a literal.