The following code compiles with gcc and clang, but not with msvc. For msvc the initialization of the char array member variable with a string literal seems to result in the implicitly generated default constructor not being constexpr according to the compiler:
struct S
{
#if 1
char str[2] = "1";
#else
char str[2] { 'a', '\0'};
#endif
};
int main()
{
constexpr S s; // line 12: compiler error in msvc
constexpr S s2{};
}
MSVC output
example.cpp
<source>(12): error C2131: expression did not evaluate to a constant
<source>(12): note: failure was caused by call of undefined function or one not declared 'constexpr'
<source>(12): note: see usage of 'S::S'
Compiler returned: 2
Both using aggregate initialization for the containing object and initializing the array as array of character literals is accepted by all compilers.
Which compiler is right according to the C++ 20 standard?