<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107593>107593</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Unexpected error: (constexpr) placement new would change type of storage
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          pkeir
      </td>
    </tr>
</table>

<pre>
    The C++26 code below fails to compile: 

```cpp
#include <memory>

constexpr bool test()
{
 int* p = std::allocator<int>{}.allocate(3);
  new (p) int[]{1, 2, 3};
 std::allocator<int>{}.deallocate(p, 3);
  return true;
}
static_assert(test());
```

The code is using [P2747](https://wg21.link/P2747) constexpr placement new, as a test; from a code excerpt in the proposal. The code compiles on GCC. A Compiler Explorer example without the `<memory>` dependency is available [here](https://godbolt.org/z/Mna6TaPx1). The invocation and error message is:

```
clang++ -c -stdlib=libc++ -std=c++26 cpn-test.cpp 
cpn-test.cpp:11:15: error: static assertion expression is not an integral constant expression
   11 | static_assert(test());
      | ^~~~~~
cpn-test.cpp:6:3: note: placement new would change type of storage from 'int' to 'int[3]'
    6 |   new (p) int[]{1, 2, 3};
      | ^
cpn-test.cpp:11:15: note: in call to 'test()'
   11 | static_assert(test());
      |               ^~~~~~
1 error generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVU2P4zYM_TXMhZjApmI7PviQj0lPBfawPReyzXHUVSRBkieZHvrbC9meSWaxwG5RIVBkmSIfHx9lGYIaDHMDxR6K40qO8Wx9476x8qvW9m_N1zPjAWgPtKcSO9sztqztFV-k0gGjxc5enNIMYoeQHSHbLXOZzb_OuWWHhDKdHntGEIcLX6x_A_H8eKizJkS-OY-ttRojhwi0BaoXo2o_L1CZCLRDhyCOGGIPYgdiJ7W2nYzWgzgkC_GcTlTH9fKCgbYieRPvftDwFYG2DqienE48QLXPgQ5I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