Isn't that a literal type?

This code does not compile in Coliru , although it seems to correspond to iso §5.19 p2 of the 9th marker point and iso §3.9 p10, i.e. Sis a literal type, so S a(1);it should be considered a constant expression. In particular, iso §3.9 p10 bullet point 3 says nothing about unified members.

#include <iostream>

struct S
{
    int i;
    float x;

    constexpr S(int j) : i{j} {}
};    

int main()
{
    constexpr S a(1);
}
+4
source share
1 answer

This is standardized in 7.1.5 / 4 ([dcl.constexpr], "Specifier constexpr"):

The constexpr constructor definition must satisfy the following restrictions:

  • [...]

  • each non-static data element and sub-object of the base class must be initialized

  • [...]

+9
source

All Articles