I have a strange error returned by gcc/clang When I switch from std=c++17 to std=c++20.
struct Matrix2 {
double ptr[9];
// defaults
Matrix2() = default; // constructor
Matrix2(const Matrix2&) = default; // copy constructor
Matrix2(Matrix2&&) = default; // move constructor
Matrix2& operator=(const Matrix2&) = default; // copy assignment operator
Matrix2& operator=(Matrix2&&) = default; // move assignment operator
~Matrix2() = default; // destructor
};
constexpr Matrix2 Id2() {
return { 1.0 , 0.0 , 0.0 ,
0.0 , 1.0 , 0.0 ,
0.0 , 0.0 , 1.0 };
}
int main () {
auto a = Id2();
}
with stdc++17, the code compile fine, but with stdc++20 this produce the following error :
could not convert '{1.0e+0, 0.0, 0.0, 0.0, 1.0e+0, 0.0, 0.0, 0.0, 1.0e+0}' from '<brace-enclosed initializer list>' to 'Matrix2'
https://godbolt.org/z/P4afYYn9d
Does the standard now prohibit returning raw initializer_list ?? and what is the work around ??
Thx a lot