[Bug c++/86147] New: Lambda is capturing a non-ODR-used constexpr
julian.panetta at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 14 11:31:00 GMT 2018
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.
More information about the Gcc-bugs
mailing list