I have the following program that compiles with gcc and clang but doesn't compile with msvc c++20. Live demo
struct not_default_constructible { not_default_constructible() = delete; };
template<typename T> struct C
{
static constexpr T t{};
};
template<class T>
struct myClass {
C<T> new_t() { return {}; }
};
int main() {
myClass<not_default_constructible> d;
d.new_t();
}
As we can see, the above program works with gcc and clang with both c++17 as well as c++20 but rejected by msvc with c++20 with the error:
<source>(6): error C2131: expression did not evaluate to a constant
<source>(6): note: failure was caused by call of undefined function or one not declared 'constexpr'
<source>(6): note: see usage of 'not_default_constructible::not_default_constructible'
<source>(15): note: see reference to class template instantiation 'C<T>' being compiled
with
[
T=not_default_constructible
]
So I want to know which compiler is right here in C++20. I mean is the program well-formed in c++20.