Bug 118237 - failure to compile constexpr variable initialization with properly destroyed allocation inside the expression
Summary: failure to compile constexpr variable initialization with properly destroyed ...
Status: RESOLVED DUPLICATE of bug 105826
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2024-12-29 17:16 UTC by Hana Dusíková
Modified: 2024-12-29 17:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-12-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hana Dusíková 2024-12-29 17:16:35 UTC
Hi,

I was looking into dynamic allocation tracking, and found simple example which fails to compile:

`constexpr auto f = (delete new int{42}, 32);`

It seems GCC is not tracking dynamic allocations inside RHS of constexpr variable definition. This should be valid according to [expr.const] as the allocation is destroyed within evaluation of E (here `(delete new int{42}, 32)`)

Other compilers do accept this snipper:

https://compiler-explorer.com/z/zeae1MP9d

The bug is present in all versions of GCC since support dynamic allocations inside constant evaluation (GCC 10).
Comment 1 Hana Dusíková 2024-12-29 17:17:12 UTC
Error I'm getting is:

```
<source>:1:43: error: the value of '<anonymous>' is not usable in a constant expression
    1 | constexpr auto f = (delete new int{42}, 32);
      |                                           ^
<source>:1:38: note: '<anonymous>' was not declared 'constexpr'
    1 | constexpr auto f = (delete new int{42}, 32);
      |                                      ^
Compiler returned: 1
```
Comment 2 Drea Pinski 2024-12-29 17:55:18 UTC
Dup.

*** This bug has been marked as a duplicate of bug 105826 ***