public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97790] New: constexpr evaluation reports false positive memory leak
@ 2020-11-10 21:09 ldalessandro at gmail dot com
  2020-11-10 21:31 ` [Bug c++/97790] " ldalessandro at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-10 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97790
           Summary: constexpr evaluation reports false positive memory
                    leak
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldalessandro at gmail dot com
  Target Milestone: ---

The constexpr evaluator seems to lose track of dynamic allocations in some
contexts, resulting in false-positive leaks and rejected valid code. 

This particular example uses an immediately invoked function expression
referencing an NTTP, which seems like a corner case but is actually extremely
common in two-pass constexpr algorithms (i.e., compute constexpr size of
result, then compute result to return).

https://godbolt.org/z/Tnn6xh

```
struct vector {
    int *data;
    int n;
    constexpr vector() : data(new int[1]{}), n(1) {}
    constexpr ~vector() { delete [] data; }
};

struct Foo {
    constexpr auto foo() const {
        return vector();
    }
};

template <auto& f>
constexpr static auto bar() {
    [] { return f.foo().n; }();
    return true;
}

constexpr Foo foo;
constexpr auto dd = bar<foo>();
```

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

end of thread, other threads:[~2020-11-12 10:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 21:09 [Bug c++/97790] New: constexpr evaluation reports false positive memory leak ldalessandro at gmail dot com
2020-11-10 21:31 ` [Bug c++/97790] " ldalessandro at gmail dot com
2020-11-11 12:22 ` jakub at gcc dot gnu.org
2020-11-11 13:04 ` jakub at gcc dot gnu.org
2020-11-12  9:48 ` cvs-commit at gcc dot gnu.org
2020-11-12 10:06 ` cvs-commit at gcc dot gnu.org
2020-11-12 10:54 ` jakub 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).