Leak FP when using a lambda capture
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/W3Y847sMT
```c++
struct Ptr {
int* p;
explicit Ptr(int* p) : p(p) {}
Ptr(Ptr&& o) : p(o.p) { o.p = nullptr; }
~Ptr() { delete p; }
};
void top() {
auto l = [q = Ptr(new int)] {}; // FP: Potential leak of memory pointed to by field 'p' [cplusplus.NewDeleteLeaks]
l();
}
```
A similar issue was in the past #60896 for unique_ptr leaks and those were suppressed in #152751 but that only suppresses for standard smart-pointers, thus a custom uptr like class like `Ptr` here still warns.
Contributor guide
Research direction
Start by reproducing the Godbolt example and inspect the cplusplus.NewDeleteLeaks checker behavior for the lambda capture. Compare the handling with the suppression added for #60896 in #152751. Done means the custom Ptr example no longer produces this false-positive leak warning, with a regression test covering it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100