The following code compiles fine:
struct A {
int i;
constexpr A() : i(1) { }
constexpr A(const A& that) : i(1) { }
};
constexpr auto func() {
std::array<A, 3> result = {};
return result;
}
However, if we add a template type parameter T to A,
template<typename T> struct A {
int i;
constexpr A() : i(1) { }
constexpr A(const A<T>& that) : i(1) { }
};
constexpr auto func() {
std::array<A<int>, 3> result = {};
return result;
}
the compiler errors "constexpr function 'func' cannot result in a constant expression".
How is this possible?