[llvm-bugs] [Bug 38611] New: False positive

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 16 21:12:39 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38611

            Bug ID: 38611
           Summary: False positive
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: me at sunchangming.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
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/20180817/b2520b63/attachment.html>


More information about the llvm-bugs mailing list