2860. launder and base class subobjects

Section: 21.6.4 [ptr.launder] Status: Core Submitter: Hubert Tong Opened: 2017-01-31 Last modified: 2017-10-27

Priority: 2

View other active issues in [ptr.launder].

View all other issues in [ptr.launder].

View all issues with Core 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:

  1. always, or

  2. 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) to Core.

[2017-08-14, CWG telecon note]

Core recommends NAD after discussion in EWG.

Proposed resolution:

This wording is relative to N4618.

  1. Option 1:

    1. Modify 21.6.4 [ptr.launder] as indicated:

      template <class T> constexpr T* launder(T* p) noexcept;
      

      -1- Requires: p represents the address A of a byte in memory. An object X that is within its lifetime (6.6.3 [basic.life]) and whose type is similar (7.5 [conv.qual]) to T is located at the address A. 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 through p (see below).

  2. Option 2:

    1. Modify 21.6.4 [ptr.launder] as indicated:

      template <class T> constexpr T* launder(T* p) noexcept;
      

      -1- Requires: p represents the address A of a byte in memory. An object X that is within its lifetime (6.6.3 [basic.life]) and whose type is similar (7.5 [conv.qual]) to T is located at the address A. If T is a polymorphic class type, then X shall be a most derived object. All bytes of storage that would be reachable through the result are reachable through p (see below).