<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 coming when -isystem is used"
   href="https://bugs.llvm.org/show_bug.cgi?id=47597">47597</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive coming when -isystem is used
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>cassio.neri@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

// file: leak.cpp
#include <benchmark/benchmark.h> // Google benchmark library

void foo(benchmark::State& state);

int main() {
  benchmark::RegisterBenchmark("foo", foo);
}

$ scan-build clang++ -isystem <path-to-benchmark> -c leak.cpp
scan-build: Using '/usr/bin/clang-8' for static analysis
In file included from leak.cpp:1:
path-to-benchmark/benchmark/benchmark.h:974:3: warning: Potential memory leak
  return internal::RegisterBenchmarkInternal(
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Replacing -isystem with -I silences the warning. If anything, I'd expect
-isystem to issue less warnings than -I and not the other way round. I've
managed to pinpoint the issue (imitating benchmark) in this SSCCE:

// file: leak.hpp
#pragma GCC system_header // removing this line silences the warning

void foo(int*);

void bar() {
  foo(new int);
}

// file: leak.cpp
#include "leak.hpp"

int main() {
  bar();
}

$ scan-build clang++ -c leak.cpp
scan-build: Using '/usr/bin/clang-8' for static analysis
In file included from leak_tmp.cxx:1:
./leak.hpp:7:1: warning: Potential memory leak
}
^

As said above, I'd expect less warnings with the #pragma than without it.
Actually, in this case, I would prefer no warning at all. It is possible, after
all, that foo frees the memory.

FWIW:
1) '-disable-checker unix.Malloc' does not silence the warning.
2) Same behavior with clang-10.</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>