<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - False positive"
href="https://bugs.llvm.org/show_bug.cgi?id=38611">38611</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dcoughlin@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>me@sunchangming.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Test code:
```
#include <string>
#include <iostream>
#include <memory>
class Status {
public:
~Status(){delete state_;}
bool IsOK() const {
return (state_ == 0);
}
static Status OK() {
return Status();
}
private:
const std::string* state_ = 0;
};
Status Convert(int ** out) {
*out = new int;
**out = 1;
return Status::OK();
}
int main(int argc,char* argv[]){
int* tensor = 0;
const Status st = Convert(&tensor);
if (!st.IsOK()) return -1;
delete tensor;
return 0;
}
```
Output:
/usr/libexec/c++-analyzer -Wall -Wextra -o main.o -c
/data/clang_test/main.cpp
/data/clang_test/main.cpp: In function ‘int main(int, char**)’:
/data/clang_test/main.cpp:27:14: warning: unused parameter ‘argc’
[-Wunused-parameter]
int main(int argc,char* argv[]){
~~~~^~~~
/data/clang_test/main.cpp:27:25: warning: unused parameter ‘argv’
[-Wunused-parameter]
int main(int argc,char* argv[]){
~~~~~~^~~~~~
/data/clang_test/main.cpp:30:27: warning: Potential leak of memory pointed to
by 'tensor'
if (!st.IsOK()) return -1;
^
1 warning generated.
However, if I remove the destructor, everything is fine.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>