Рассмотрим этот код: < /p>
#include
template < int... Ints >
constexpr std::array theIntArray = {Ints...};
template < size_t NN >
constexpr void test(const std::array& xx)
{
theIntArray;
}
constexpr std::array aa = {10,20};
int main()
{
theIntArray; // passes
test(aa); // FAILS ?!
return 0;
}
< /code>
В main () < /code> функция первая строка проходит, в то время как вторая строка не выполняется со странным сообщением об ошибке: < /p>
error: ‘* & xx’ is not a constant expression
note: in template argument for type ‘int’
< /code>
Я использую GCC-7.0.1, и вы можете найти живой пример здесь. < /p>
это в соответствии с стандартом или это ошибка? Что заставляет вторую строчку провалиться, пока первая строка проходит?
Подробнее здесь: https://stackoverflow.com/questions/421 ... to-compile