This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114b. See for the official list.


2325. std::launder and reuse of character buffers

Section: 6.7.2  [intro.object]     Status: drafting     Submitter: CA     Date: 2017-02-27

P0488R0 comment CA 12

The status of the following code should be explicitly indicated in the Standard to avoid surprise:

  #include <new>
  int bar() {
    alignas(int) unsigned char space[sizeof(int)];
    int *pi = new (static_cast<void *>(space)) int;
    *pi = 42;
    return [=]() mutable {
      return   *std::launder(reinterpret_cast<int *>(space)); }();

In particular, it appears that the call to std::launder has undefined behaviour because the captured copy of space is not established to provide storage for an object of type int (sub 6.7.2 [intro.object] paragraph 1). Furthermore, the code has undefined behaviour also because it attempts to access the stored value of the int object through a glvalue of an array type other than one of the ones allowed by sub 7.2.1 [basic.lval] paragraph 8.