Issue 108823
Summary [clang-tidy] false positive report of possible memory leak when capturing std::function in lambda multiple times
Labels clang-tidy
Assignees
Reporter valarx
    Minimal reproduction example:

```
#include <functional>

std::function<void()> combine(const std::function<void()>& lhs, const std::function<void()>& rhs)
{
    auto thisTemporaryCausesWarning = [lhs, rhs] (){};
    return { std::move(thisTemporaryCausesWarning) };

int main()
{
 std::function<void()> f;
    f = combine(f, nullptr);
    f = combine(f, nullptr); // this call triggers warning
}
```

As described, when calling `combine` two times in this scenario, if the temporary variable is present in `combine` implementation, then clang-tidy triggers warning "potential memory leak" which points to implementation of constructor of `std::function`. If the temporary variable is not present, then the warning is not triggered.

Clang-tidy version is 18.1
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to