I have a class that contains a static member which is set to the class itself evaluated in a specific way. This is an example
struct A{
constexpr A(const int i):_i(i){}
int _i;
static const A One;
};
constexpr A A::One=A(1);
This code compiles and runs with gcc and clang, but if I compile with the Intel compiler icc (v19.0.4.227) (or on Godbolt with ICC19.0.1) I get
icc -std=c++17 test.cpp
test.cpp(10): error: member "A::One" (declared at line 7) was previously not declared constexpr
constexpr A A::One=A(1);
Note that I cannot initialize A::One in the struct A{} definition since the type would be incomplete.
Is there a workaround that would work with the Intel compiler?
A main
that uses this would look like, if you wanted to actually run this instead of just compile.
int main()
{
std::cout << A::One._i << std::endl;
return 0;
}