Title
start_lifetime_as, placement-new, and active union members
Status
open
Section
11.5.1 [class.union.general]
Submitter
Nina Ranns

Created on 2022-12-06.00:00:00 last changed 17 months ago

Messages

Date: 2022-12-06.00:00:00

Consider:

  struct A { int i;};
  struct B { int j;};
  union U { A a; B b; };
  U u1{A{}};
  start_lifetime_as<B>(&u1.a); // #1
  start_lifetime_as<B>(&u1);   // #2
  U u2{B{}};
  start_lifetime_as<U>(&u2);   // #3
  start_lifetime_as<B>(&u1.b); // #4

It is unclear which of these constructs changes the active member of the union, and whether a union might have more than one active member. Subclause 11.5.1 [class.union.general] paragraph 2 appears contradictory if several members can be in-lifetime:

In a union, a non-static data member is active if its name refers to an object whose lifetime has begun and has not ended (6.7.3 [basic.life]). At most one of the non-static data members of an object of union type can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time.

Similar questions arise for placement-new and for construct_at; for the latter also during constant evaluation.

History
Date User Action Args
2022-12-06 00:00:00admincreate