[Bug c++/71504] bogus error: accessing value through a glvalue in a constant expression
will at dash dot org
gcc-bugzilla@gcc.gnu.org
Sun Apr 1 17:23:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71504
--- Comment #6 from Will <will at dash dot org> ---
A simpler example exhibiting this bogus error; an innocent, idiomatic,
pedantic, platonic pair of nested range-for loops iterating a 2D array:
g++ prog.cc -Wall -Wextra -std=c++14 -pedantic-errors
#include <type_traits>
template <typename A>
constexpr auto sum(A const& a)
{
int tot = 0;
for (auto& row : a)
for (auto elem : row)
tot += elem;
return tot;
}
constexpr int const a22[2][2] = {{1,2},{3,4}};
static_assert( sum(a22) == 10, "badsum");
prog.cc:17:18: in 'constexpr' expansion of 'sum<int [2][2]>(a22)'
prog.cc:17:24: error: accessing value of 'a22' through a 'const int' glvalue in
a constant expression
More information about the Gcc-bugs
mailing list