llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.76k stars 10.97k forks source link

clang-analyzer-cplusplus.NewDeleteLeaks incorrectly reports leak #54481

Open sam1018 opened 2 years ago

sam1018 commented 2 years ago

For the following code:

std::shared_ptr create_sp() { return std::make_shared(10); }

std::vector<std::shared_ptr> f() { return {create_sp()}; }

clang-analyzer is incorrectly raising NewDeleteLeaks warning. happens with-std=c++17 flag. Here is godbolt link showing the issue: https://godbolt.org/z/K88K86xrG

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-static-analyzer

gregor2904 commented 1 year ago

I have the same problem. If I store result of make_shared into a variable and use this variable then - no leak report occurs. But it is not a good solution.