Created on 2022-12-06.00:00:00 last changed 21 months ago
Suggested resolution:
Change in 6.7.2 [intro.object] paragraph 2 as follows:
Objects can contain other objects, called subobjects. A subobject can be a member subobject (11.4 [class.mem]), a base class subobject (11.7 [class.derived]), or an array element. An object that is not a subobject of any other object is called a complete object. If an object is created in storage associated with amember subobject or array elementsubobject e (which may or may not be within its lifetime), the created object is a subobject of e's containing object if:In this case, e and the created object are corresponding direct subobjects.
- the lifetime of e's containing object has begun and not ended, and
- the storage for the new object exactly overlays the storage location associated with e, and
- e is not a potentially-overlapping subobject, and
- the new object is of the same type as e (ignoring cv-qualification).
Change in 6.7.4 [basic.life] paragraph 8 as follows:
... An object o1 is transparently replaceable by an object o2 if either
- o1 and o2 are complete objects for which:
- o1 is not const,
- the storage that o2 occupies exactly overlays the storage that o1 occupied, and
- o1 and o2 are of the same type (ignoring the top-level cv-qualifiers),
andoro1 is not a const, complete object, andneither o1 nor o2 is a potentially-overlapping subobject (6.7.2 [intro.object]), andeither o1 and o2 are both complete objects, oro1 and o2 are corresponding direct subobjectsof objects p1 and p2, respectively, and p1 is transparently replaceable by p2(6.7.2 [intro.object]) for which:
- the complete object of o1 is not const or
- o1 is a mutable member subobject or a subobject thereof.
Additional notes (February, 2023)
The suggested resolution above does not handle the additional example in issue 2676.
Suggested resolution [SUPERSEDED]:
Change in 6.7.4 [basic.life] paragraph 8 as follows:
... An object o1 is transparently replaceable by an object o2 if:
- o2 is a complete object and:
- the storage that o2 occupies exactly overlays the storage that o1 occupied, and
- o1 and o2 are of the same type (ignoring the top-level cv-qualifiers), and
- o1 is not a const, complete object, and
neithero1nor o2is not a potentially-overlapping subobject (6.7.2 [intro.object]),andoreither o1 and o2 are both complete objects, oro1 and o2 are corresponding direct subobjects of objects p1 and p2, respectively, and p1 is transparently replaceable by p2.
The resolution to NB comment US 041 (C++20 CD) does not seem to have fully addressed the original issue, allowing:
union U { int i, j; }; U u; new (&u) U{.i = 5}; int k = u.j; // OK! New U::i transparently replaces existing u.j!
The suggestion is to allow a newly-created complete object to transparently replace any object of the same type in the same storage, except for a potentially-overlapping subobject or a const complete object, and to allow a newly-created subobject to transparently replace only a corresponding subobject of an existing object.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-03-03 21:06:51 | admin | set | status: open -> review |
2023-02-23 21:27:05 | admin | set | messages: + msg7207 |
2023-02-23 21:27:05 | admin | set | messages: + msg7206 |
2023-01-07 20:23:15 | admin | set | messages: + msg7125 |
2022-12-06 00:00:00 | admin | create |