[Bug c++/106485] New: Can't use heap pointer in `static_assert`
johelegp at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Jul 30 19:58:55 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106485
Bug ID: 106485
Summary: Can't use heap pointer in `static_assert`
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/W4r6oMa3M.
```C++
struct I {
int* i = new int{1};
constexpr ~I() { delete i; }
};
static_assert([] { return I{}.i; }());
static_assert(I{}.i);
```
```
<source>:5:19: error: non-constant condition for static assertion
5 | static_assert(I{}.i);
| ~~~~^
<source>:5:19: error: the value of '<anonymous>' is not usable in a constant
expression
<source>:5:17: note: '<anonymous>' was not declared 'constexpr'
5 | static_assert(I{}.i);
| ^
Compiler returned: 1
```
It works wrapped in an IILE, or if the `int` is uninitialized.
More information about the Gcc-bugs
mailing list