https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99031
Bug ID: 99031
Summary: Comparing pointers to heap-allocated memory is not a
constant expression
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: david at doublewise dot net
Target Milestone: ---
The following valid translation unit
```
constexpr bool f() {
auto a = new int;
auto b = new int;
if (a == b) {
}
delete b;
delete a;
return true;
}
static_assert(f());
```
is rejected with
```
<source>:11:16: error: non-constant condition for static assertion
11 | static_assert(f());
| ~^~
<source>:11:16: in 'constexpr' expansion of 'f()'
<source>:4:15: error: '(((int*)(& heap )) == ((int*)(& heap )))' is not a
constant expression
4 | if (a == b) {
| ~~^~~~
Compiler returned: 1
```
See it live: https://godbolt.org/z/of45no