This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4130. Preconditions for std::launder might be overly strict

Section: 17.6.5 [ptr.launder] Status: New Submitter: Jiang An Opened: 2024-07-30 Last modified: 2024-10-02

Priority: 3

View all other issues in [ptr.launder].

View all issues with New status.

Discussion:

From issue cplusplus/draft#4553 which is considered non-editorial.

Currently, std::launder has a precondition that the pointed to object must be within its lifetime. However, per the example added by P0593R6, it's probably intended that the result of std::launder should be allowed to point to an array element subobject whose lifetime has not started yet.

[2024-10-02; Reflector poll]

Set priority to 3 after reflector poll. Needs review by Core.

Proposed resolution:

This wording is relative to N4986.

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

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

    -1- Mandates: !is_function_v<T> && !is_void_v<T> is true.

    -2- Preconditions: p represents the address A of a byte in memory. An object X that is within its lifetime (6.7.3 [basic.life]) and whose type is similar (7.3.6 [conv.qual]) to T is located at the address A, and is either within its lifetime (6.7.3 [basic.life]) or is an array element subobject whose containing array object is within its lifetime. All bytes of storage that would be reachable through (6.8.4 [basic.compound]) the result are reachable through p.

    -3- Returns: A value of type T* that points to X.

    […]