public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106485] New: Can't use heap pointer in `static_assert`
@ 2022-07-30 19:58 johelegp at gmail dot com
  2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: johelegp at gmail dot com @ 2022-07-30 19:58 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-19  1:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-30 19:58 [Bug c++/106485] New: Can't use heap pointer in `static_assert` johelegp at gmail dot com
2022-07-30 22:16 ` [Bug c++/106485] " pinskia at gcc dot gnu.org
2022-09-08 16:38 ` johelegp at gmail dot com
2023-01-19  1:36 ` pinskia at gcc dot gnu.org
2023-01-19  1:48 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).