include <benchmark/benchmark.h> // Google benchmark library
void foo(benchmark::State& state);
int main() {
benchmark::RegisterBenchmark("foo", foo);
}
$ scan-build clang++ -isystem -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.
Extended Description
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 -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.