Title
Clarify that std::launder is not needed when using the result of std::memcpy
Status
ready
Section
[cstring.syn]
Submitter
Jan Schultke

Created on 2024-04-05.00:00:00 last changed 4 weeks ago

Messages

Date: 2024-06-28.22:21:53

Proposed resolution:

This wording is relative to N4981.

  1. Modify [cstring.syn] as indicated:

    -3- The functions memcpy and memmove are signal-safe ([support.signal]). Both Each of these functions implicitly create creates objects ([intro.object]) in the destination region of storage immediately prior to copying the 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.

Date: 2024-06-28.22:21:53

[ St. Louis 2024-06-28; LWG: move to Ready ]

Date: 2024-06-26.20:44:45

[ St. Louis 2024-06-26; CWG suggested improved wording ]

Date: 2024-06-15.00:00:00

[ 2024-06-24; Reflector poll ]

Set priority to 3 after reflector poll.

This wording is relative to N4971.

  1. Modify [cstring.syn] as indicated:

    -3- The functions memcpy and memmove are signal-safe ([support.signal]). Both functions implicitly create objects ([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.

Date: 2024-04-11.17:55:57
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 of std::launder. std::memcpy implicitly creates an int inside y, and https://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 [cstring.syn] p3, this presumably means that std::memcpy returns a pointer to the (first) implicitly-created object, and no use of std::launder is necessary.

The wording should be clarified to clearly support this interpretation or reject it.

History
Date User Action Args
2024-06-28 22:21:53adminsetmessages: + msg14224
2024-06-28 22:21:53adminsetstatus: open -> ready
2024-06-26 20:44:45adminsetmessages: + msg14217
2024-06-26 20:44:45adminsetstatus: new -> open
2024-06-24 12:43:36adminsetmessages: + msg14195
2024-04-05 12:16:18adminsetmessages: + msg14053
2024-04-05 00:00:00admincreate