std::launder
might be overly strictSection: 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.
Modify 17.6.5 [ptr.launder] as indicated:
template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;-1- Mandates:
-2- Preconditions:!is_function_v<T> && !is_void_v<T>
istrue
.p
represents the address A of a byte in memory. An object Xthat is within its lifetime (6.7.3 [basic.life]) andwhose type is similar (7.3.6 [conv.qual]) toT
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 throughp
. -3- Returns: A value of typeT*
that points to X. […]