The following code is accepted by clang and rejected by gcc. I would like to know if this is a mistake or something is missing:
#include <array>
template<typename T>
static constexpr T Apply(T in, T fun(T)) {
return fun(in);
}
template <typename T, size_t N> struct Triangle {
using Ar = std::array<T, N>;
static constexpr Ar foo(Ar line) { return line; }
static constexpr Ar results = Apply<Ar>( {{ 1 }}, foo );
};
template <typename T, size_t N> constexpr std::array<T, N> Triangle<T, N>::results;
int main() {
Triangle<unsigned long, 10>::results[0];
}
GCC Error Message:
binom2.cpp: In instantiation of ‘constexpr const std::array<long unsigned int, 10ul> Triangle<long unsigned int, 10ul>::results’:
binom2.cpp:16:32: required from here
binom2.cpp:11:57: in constexpr expansion of ‘Apply<std::array<long unsigned int, 10ul> >(std::array<long unsigned int, 10ul>{std::__array_traits<long unsigned int, 10ul>::_Type{1ul}}, Triangle<T, N>::foo<long unsigned int, 10ul>)’
binom2.cpp:5:16: error: expression ‘Triangle<T, N>::foo<long unsigned int, 10ul>’ does not designate a constexpr function
return fun(in);
^
source
share