I have the following helper function:
template<typename T, std::size_t N>
constexpr std::size_t Length(const T(&)[N]) {
return N;
}
Which returns the length of a static array. In the past this always has worked but when I do this:
struct Foo
{
unsigned int temp1[3];
void Bar()
{
constexpr std::size_t t = Length(temp1); // Error here
}
};
I get an error when using MSVS 2017:
error C2131: expression did not evaluate to a constant note: failure was caused by a read of a variable outside its lifetime note: see usage of 'this'
I was hoping someone can shed light on what I'm doing wrong.
Lengthnoexceptas well - there's no reasonable scenario where it would ever throw an exception.-pedantic-errorsmight allow it because it supports VLA in C++. With-pedantic-errorsit fails in C++17 GCC as well.