[llvm-bugs] [Bug 38176] New: clang-analyzer-cplusplus.NewDeleteLeaks false positive in C++17 mode only
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 16 04:10:29 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38176
Bug ID: 38176
Summary: clang-analyzer-cplusplus.NewDeleteLeaks false positive
in C++17 mode only
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: florin at signbit.net
CC: llvm-bugs at lists.llvm.org
florin at helios$ cat unique.cc
#include <cstdint>
#include <iostream>
#include <memory>
using Bar = uint64_t;
class Foo
{
public:
explicit Foo(Bar bar) : bar(bar)
{
}
const Bar& getBar()
{
return bar;
}
private:
Bar bar;
};
std::unique_ptr<Foo> fooMaker()
{
Bar bar = {};
return std::make_unique<Foo>(bar);
}
int main()
{
return 0;
}
florin at helios:$ clang++-6.0 --analyze -Xanalyzer -analyzer-output=text
-std=c++14 -o unique.o unique.cc
florin at helios:$ clang++-6.0 --analyze -Xanalyzer -analyzer-output=text
-std=c++17 -o unique.o unique.cc
florin at helios:$ /opt/llvm7/bin/clang++ --analyze -Xanalyzer
-analyzer-output=text -std=c++14 -o unique.o unique.cc
florin at 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<Foo>(bar);
^
unique.cc:27:11: note: Calling 'make_unique<Foo, unsigned long &>'
return std::make_unique<Foo>(bar);
^~~~~~~~~~~~~~~~~~~~~~~~~~
/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<Foo>(bar);
^~~~~~~~~~~~~~~~~~~~~~~~~~
unique.cc:27:4: note: Potential leak of memory pointed to by field
'_M_head_impl'
return std::make_unique<Foo>(bar);
^
1 warning generated.
-----------------------------------
This is with LLVM/Clang/Clang-Extra from trunk
llvm:
commit 2d2ebb317ec78069296276ca13a8461e4a27e6c6
Author: Andrea Di Biagio <Andrea_DiBiagio at 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 at aaronballman.com>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337125
91177308-0d34-0410-b5e6-96231b3b80d8
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180716/3c77075c/attachment.html>
More information about the llvm-bugs
mailing list