https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95977

            Bug ID: 95977
           Summary: No deallocation of temporary in return-statement
                    during constant evaluation
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/iyRFxf.
```C++
struct X {
    int* x{new int{42}};
    X() = default;
    constexpr X(const X& x) : x{new int{*x.x}} { }
    constexpr ~X() { delete x; }
};
constexpr int f() { X x; return *X{x}.x; }
constexpr int z{f()};
```
```
<source>:4:45: error: 'f()' is not a constant expression because allocated
storage has not been deallocated

    4 |     constexpr X(const X& x) : x{new int{*x.x}} { }

      |                                             ^
```

Reply via email to