Title
Preconditions for std::launder might be overly strict
Status
open
Section
[ptr.launder]
Submitter
Jiang An

Created on 2024-07-30.00:00:00 last changed yesterday

Messages

Date: 2024-11-19.16:09:07

Proposed resolution:

This wording is relative to N4986.

  1. Modify [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 ([basic.life]) and whose type is similar ([conv.qual]) to T is located at the address A, and is either within its lifetime ([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 ([basic.compound]) the result are reachable through p.

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

    […]

Date: 2024-11-19.16:09:07

[ Wrocław 2024-11-18; approved by Core ]

Date: 2024-10-15.00:00:00

[ 2024-10-02; Reflector poll ]

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

Date: 2024-07-30.00:00:00

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.

History
Date User Action Args
2024-11-19 16:09:07adminsetmessages: + msg14458
2024-11-19 16:09:07adminsetstatus: new -> open
2024-10-02 12:51:34adminsetmessages: + msg14409
2024-08-03 07:14:09adminsetmessages: + msg14304
2024-07-30 00:00:00admincreate