Title
Replacing a complete object having base subobjects
Status
open
Section
6.7.3 [basic.life]
Submitter
Richard Smith

Created on 2022-12-06.00:00:00 last changed 1 month ago

Messages

Date: 2022-12-06.00:00:00

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

An object o1 is transparently replaceable by an object o2 if:
  • ...
  • neither o1 nor o2 is a potentially-overlapping subobject (6.7.2 [intro.object]), and
  • ...

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.

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