This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofWP status.
std::launder
is not needed when using the result ofstd::memcpy
Section: 27.5.1[cstring.syn]Status:WPSubmitter: Jan SchultkeOpened: 2024-04-05Last modified: 2024-11-28
Priority:3
View all issues withWP status.
Discussion:
int x = 0;alignas(int) std::byte y[sizeof(int)];int z = *static_cast<int*>(std::memcpy(y, &x, sizeof(int)));
This example should be well-defined, even without the use ofstd::launder
.std::memcpy
implicitly creates anint
insidey
, andhttps://www.iso-9899.info/n3047.html#7.26.2.1p3 states that
The
memcpy
function returns the value of [the destination operand].
In conjunction with 27.5.1[cstring.syn] p3, this presumably means thatstd::memcpy
returns a pointer to the (first) implicitly-created object, and no use ofstd::launder
is necessary.
[2024-06-24; Reflector poll]
Set priority to 3 after reflector poll.
Previous resolution [SUPERSEDED]:
This wording is relative toN4971.
Modify 27.5.1[cstring.syn] as indicated:
-3- The functions
memcpy
andmemmove
are signal-safe (17.14.5[support.signal]). Both functions implicitly create objects (6.8.2[intro.object]) in the destination region of storage immediately prior to copying the sequence of characters to the destination.Both functions return a pointer to a suitable created object.
[St. Louis 2024-06-26; CWG suggested improved wording]
[St. Louis 2024-06-28; LWG: move to Ready]
[Wrocław 2024-11-18; approved by Core (again)]
[Wrocław 2024-11-23; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative toN4981.
Modify 27.5.1[cstring.syn] as indicated:
-3-The functions
memcpy
andmemmove
are signal-safe(17.14.5[support.signal]).BothEach of these functions implicitlycreatecreates objects (6.8.2[intro.object])in the destination region of storage immediately prior to copyingthe sequence of characters to the destination.Each of these functions returns a pointer to a suitable created object,if any, otherwise the value of the first parameter.