This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.
launder
and base class subobjectsSection: 17.6.5 [ptr.launder] Status: NAD Submitter: Hubert Tong Opened: 2017-01-31 Last modified: 2020-09-06
Priority: 2
View all other issues in [ptr.launder].
View all issues with NAD status.
Discussion:
There is an apparent oversight in the wording for launder
that allows it to return base class
subobjects which differ in their polymorphic behaviour between calls to launder
.
This can be fixed by restricting launder
from returning pointers to base class subobjects:
always, or
only for polymorphic class types.
[2017-03-04, Kona]
Set priority to 2. This was discussed in EWG (via a paper). Assign this (and 2859(i)) to Core.
[2017-08-14, CWG telecon note]
Core recommends NAD after discussion in EWG.
Hubert Tong summarizes the outcome of that discussion as follows:launder
does not provide positive confirmation of the dynamic type of the object; it is intended thatlaunder
can be used to induce a devirtualization barrier even when the static type of the (sub)object to which the returned pointer refers is apparently consistent with prior accesses related to the source pointer.
[2020-02 Status to NAD on Thursday night in Prague.]
Proposed resolution:
This wording is relative to N4618.
Option 1:
Modify 17.6.5 [ptr.launder] as indicated:
template <class T> constexpr T* launder(T* p) noexcept;-1- Requires:
p
represents the addressA
of a byte in memory. An objectX
that is within its lifetime (6.7.3 [basic.life]) and whose type is similar (7.3.6 [conv.qual]) toT
is located at the addressA
.X
shall either be a most derived object, or pointer-interconvertible with a most derived object that is within its lifetime. All bytes of storage that would be reachable through the result are reachable throughp
(see below).
Option 2:
Modify 17.6.5 [ptr.launder] as indicated:
template <class T> constexpr T* launder(T* p) noexcept;-1- Requires:
p
represents the addressA
of a byte in memory. An objectX
that is within its lifetime (6.7.3 [basic.life]) and whose type is similar (7.3.6 [conv.qual]) toT
is located at the addressA
. IfT
is a polymorphic class type, thenX
shall be a most derived object. All bytes of storage that would be reachable through the result are reachable throughp
(see below).