I have the following code:
struct Foo { struct Bar { std::uint32_t x = -1; constexpr Bar(std::uint32_t x) : x(x) {} }; static constexpr Bar CONST_BAR = Bar(0); }; When I try to compile it I get the following error:
error: ‘constexpr Foo::Bar::Bar(uint32_t)’ called in a constant expression before its definition is complete
Can someone explain to me what is going on? As far as I can see Bar's constructor is defined before the first call.
static constexprfunction called in a constant expression is…an error? and constexpr struct member initialisation.Bar,Foois to be considered complete. Meaning it (albeit indirectly) depends on the completeness ofFooto be viable in a constant expression. So it cannot be used in contexts whereFoois not yet complete.