This code doesn't compile in Coliru, although it seems to comply with iso §5.19 p2 9th bullet point and iso §3.9 p10, i.e., S
is a literal type and so, S a(1);
should be considered a constant expression. In particular, iso §3.9 p10 bullet point 3 doesn't say anything about unitialized members.
#include <iostream>
struct S
{
int i;
float x;
constexpr S(int j) : i{j} {}
};
int main()
{
constexpr S a(1);
}
This is standardized in 7.1.5/4 ([dcl.constexpr], "The constexpr
specifier"):
The definition of a constexpr constructor shall satisfy the following constraints:
[...]
every non-static data member and base class sub-object shall be initialized
[...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With