Open 0x8000-0000 opened 6 years ago
Any progress?
Ken, could you please attach a preprocessed file?
I'm able to reproduce it with the example above using MSVC 14.16.27023 headers.
c:\tmp\z>clang++ --analyze -Xanalyzer -analyzer-output=text -std=c++17 test.cpp
test.cpp:20:3: warning: Potential leak of memory pointed to by field '_Myval2'
return std::make_unique~~~~~
c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory:2539:26: note:
Memory is allocated
return (unique_ptr<_Ty>(new _Ty(_STD forward<_Types>(_Args)...)));
^~~~~~~~~~~
test.cpp:20:10: note: Returned allocated memory
return std::make_unique~~~~~
test.cpp:20:3: note: Potential leak of memory pointed to by field '_Myval2'
return std::make_unique
I cannot reproduce it - neither on current clang, nor on r337125. This probably has something to do with libstdc++ vs. libc++. Could you attach a preprocessed file?
Seems to be resolved in Clang 8.0.
FYI: Exactly the same thing happens for me with the clang++-7 shipped with Ubuntu Cosmic. This is rather unfortunate, because it effectively makes the very helpful clang-analyzer-cplusplus.NewDeleteLeaks unusable for our project. Suppressing the warning where it happens is not really an option due to the amount of warnings. :-(
assigned to @devincoughlin
I reproduced the issue with clang-tidy 12.0.1 using much simpler code:
#include <memory>
std::unique_ptr<int> intMaker() {
return std::make_unique<int>();
}
The false-positive only appears if C++17 is configured for the clang compiler, not if C++14 is configured.
Extended Description
florin@helios$ cat unique.cc
include
include
include
using Bar = uint64_t;
class Foo { public: explicit Foo(Bar bar) : bar(bar) { }
const Bar& getBar() { return bar; }
private: Bar bar; };
std::unique_ptr fooMaker()
{
Bar bar = {};
return std::make_unique(bar);
}
int main() { return 0; }
florin@helios:$ clang++-6.0 --analyze -Xanalyzer -analyzer-output=text -std=c++14 -o unique.o unique.cc(bar);
^
unique.cc:27:11: note: Calling 'make_unique<Foo, unsigned long &>'
return std::make_unique(bar);
^(bar);
^(bar);
^
1 warning generated.
florin@helios:$ clang++-6.0 --analyze -Xanalyzer -analyzer-output=text -std=c++17 -o unique.o unique.cc
florin@helios:$ /opt/llvm7/bin/clang++ --analyze -Xanalyzer -analyzer-output=text -std=c++14 -o unique.o unique.cc
florin@helios:$ /opt/llvm7/bin/clang++ --analyze -Xanalyzer -analyzer-output=text -std=c++17 -o unique.o unique.cc
Writing to last piece unique.cc:27:4: warning: Potential leak of memory pointed to by field '_M_head_impl' return std::make_unique
~~~~~/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unique_ptr.h:831:30: note: Memory is allocated{ return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } ^
~~~~~~~~~~ unique.cc:27:11: note: Returned allocated memory return std::make_unique~~~~~unique.cc:27:4: note: Potential leak of memory pointed to by field '_M_head_impl' return std::make_uniqueThis is with LLVM/Clang/Clang-Extra from trunk
llvm: commit 2d2ebb317ec78069296276ca13a8461e4a27e6c6 Author: Andrea Di Biagio Andrea_DiBiagio@sn.scee.net git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337124 91177308-0d34-0410-b5e6-96231b3b80d8
clang: commit 27d1a66dffa9424bcdadc7cd52cf2ae019e49889 Author: Aaron Ballman aaron@AaronBallman.com git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337125 91177308-0d34-0410-b5e6-96231b3b80d8