https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129082
Bug ID: 129082
Summary: Deleting a pointer originating from
allocator::allocate not rejected in constant
evaluation
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gongke at ios dot ac.cn
Target Milestone: ---
This is the converse of #95797.
[godbolt](https://godbolt.org/z/fzxYoM6Wf)
```cpp
#include <memory>
constexpr int f() {
int* p = std::allocator<int>{}.allocate(1);
delete p; // UB: p did not originate from a
new-expression
return 0;
}
static_assert(f() == 0); // forces constant evaluation of f()
int main() { return 0; }
```
Here the pointer `p` comes from `std::allocator::allocate` instead of a `new`
expression, so `delete`ing it is undefined behavior and should be rejected in
constant evaluation. Clang emits a clear diagnostic message on this.