This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2665. Replacing a subobject with a complete object

Section: 6.7.4  [basic.life]     Status: NAD     Submitter: Richard Smith     Date: 2022-12-06

Subclause 6.7.4 [basic.life] bullet 8.5 says that o1 is only transparently replaceable by o2 if

either o1 and o2 are both complete objects, or o1 and o2 are direct subobjects of objects p1 and p2, respectively, and p1 is transparently replaceable by p2.

This disallows most of the intended uses of the transparent replacement rule, including example 3 in 11.5.1 [class.union.general], which is similar to:

  union A { int n; string s; };
  A a;
  // Does not transparently replace A::s subobject, because
  // the created object is a complete object.
  new (&a.s) string("hello");
  string t = a.s;

The rule was changed in response to NB comment US 041 (C++20 CD) in what appears to be an over-reach: US 041 says that a member subobject should not transparently replace an unrelated member subobject, but is silent about complete objects transparently replacing members.

CWG 2023-01-06

Issues 2676 and 2677 were split off from this issue.

Subclause 6.7.2 [intro.object] paragraph 2 specifies that "the created object is a subobject of [the original] containing object" for the example above. This issue is therefore NAD.