The following code compiles in gcc 9.3, but not in gcc 10.2:
constexpr std::array<int, 2> opt = {1,2};
template <typename T>
constexpr auto f(const T& arr)
{
std::array<int, arr.size()> res{};
return res;
}
int main()
{
auto res = f(opt);
}
The code is in https://godbolt.org/z/8hb6M8.
The error given by gcc10.2 is that arr.size() is not a constant expression.
Which compiler is right? 9.3 or 10.2?
If 10.2 is right, how can I define a compile time array and pass its size (and the array) as an argument?