Can aggregate initialization refer to the previous item in aggregate?

Is the following legal?

class Aggregate {
public:
    int a;
    int b;
};

class Class {
public:
    Class():
        m_aggregate{
            3,
            // Here, m_aggregate.a is fully constructed, but m_aggregate is not
            m_aggregate.a + 5
        } {
    }
    Aggregate m_aggregate;
};

Is it legal to use aggregate elements after their life, but before the completion of the constructor of the aggregate as a whole?

Testing with gcc 4.8.2 seems to behave correctly ...

+3
source share
1 answer

I do not consider this legal. It is true that the elements of a coordinated list are initialized in order (i.e., the evaluation of the elements of the list is ordered, see 8.5.4 / 4), but the aggregate is created only after the list has been completely built. Wed 8.5.1:

, 8.5.4, , . .

- -, .

+5

All Articles