Consider this code:
#include <array>
template < int... Ints >
constexpr std::array<int,sizeof...(Ints)> theIntArray = {Ints...};
template < size_t NN >
constexpr void test(const std::array<int,NN>& xx)
{
theIntArray<xx[0]>;
}
constexpr std::array<int,2> aa = {10,20};
int main()
{
theIntArray<aa[0]>; // passes
test(aa); // FAILS ?!
return 0;
}
In the main()
function the first line passes while the second line fails with a strange error message:
error: ‘* & xx’ is not a constant expression
note: in template argument for type ‘int’
I am using gcc-7.0.1 and you can find live example here.
Is this according to the standard or it is a bug? What makes the second line fail while the first line passes?