This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2676. Replacing a complete object having base subobjects

Section: 6.7.3  []     Status: open     Submitter: Richard Smith     Date: 2022-12-06

Base subobjects cannot be transparently replaced with complete objects, as specified in 6.7.3 [] bullet 8.4:

An object o1 is transparently replaceable by an object o2 if:

However, that bullet is over-reaching, because it disallows:

  struct A { int n; };
  struct B : A {};
  B b;
  new (&b) B { {5} };  // New A base class does not transparently replace existing A base class due to /8.4.
  int k = b.n;  // UB: member n of A base class is outside its lifetime

See issue 2677 for a suggested resolution.

Additional notes (February, 2023)

Consider this example:

  struct A {
   int n;
   char c;
   // tail padding
  struct B {
   [[no_unique_address]] A a;
   char in_tail_padding[3];

  B b;
  void f() {
   // Transparently replaces old member, potentially overwriting the data in the tail padding!
   new (&b.a) A{};

The suggestions do not address this example.