Clang is more useful:
27 : error: constexpr variable 'b' must be initialized by a constant expression constexpr static B b {B(0x00, 0x00)}; ^~~~~~~~~~~~~~~~ 27 : note: undefined constructor 'B' cannot be used in a constant expression constexpr static B b {B(0x00, 0x00)}; ^ 8 : note: declared here B(uint8_t _a, uint8_t _b) : ^
Inside a member-variable-symbol-member-member element, constructors (including constructors of nested classes) are considered undefined; this is because the constructor refers to the values ββof member variables, so member variables must be defined first, even if they are lexically later in the file:
struct A { struct B { int i; constexpr B(): i{j} {} }; constexpr static int j = 99; };
A workaround is to place B outside A or possibly in the base class.
source share