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

Reply via email to