Open Quuxplusone opened 6 years ago
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. :-(
Seems to be resolved in Clang 8.0.
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?
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<Foo>(bar);
^
test.cpp:20:10: note: Calling 'make_unique<Foo, unsigned long long &, 0>'
return std::make_unique<Foo>(bar);
^~~~~~~~~~~~~~~~~~~~~~~~~~
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<Foo>(bar);
^~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:20:3: note: Potential leak of memory pointed to by field '_Myval2'
return std::make_unique<Foo>(bar);
^
1 warning generated.
Ken, could you please attach a preprocessed file?
Attached pp.zip
(130021 bytes, application/x-zip-compressed): Preprocessed file, made with clang++ --analyze -Xanalyzer -analyzer-output=text -std=c++17 -E test.cpp
Any progress?
I think we can close this issue: I have just tried clang++-11.0.1 and clang++-12.0.0 with the OP's program on Ubuntu Hirsute (21.04), and both work as expected without any warnings.
No idea what fixed that, either some change in Clang since clang-7 or some change in libstdc++, but who cares. ;-)
pp.zip
(130021 bytes, application/x-zip-compressed)