| Issue |
107593
|
| Summary |
Unexpected error: (constexpr) placement new would change type of storage
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
pkeir
|
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.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs