Search code examples
c++cppcheck

Cppcheck inline suppression when using compile_commands.json


I am trying to learn about cppcheck and therefore I am integrating it into the the travis build of my example project. I fixed a lot of issues thanks to cppcheck, but there are some false positives that I would like to ignore via inline suppression.

a.cpp

struct A {
  int i;
};

// cppcheck-suppress unusedFunction
A operator+(const A &a1, const A &a2) {
  return A{a1.i + a2.i};
}

int main() {
  return 0;
}

compile_commands.json

[
  {
    "directory": "/path/to/source",
    "command": "/usr/bin/clang++-9 -std=gnu++17 -o a.o -c a.cpp",
    "file": "a.cpp"
  }
]

When I run cppcheck (version 1.82) as cppcheck --enable=all --inline-suppr a.cpp then it is fine. But when I run it with the compile_commands.json file like cppcheck --enable=all --inline-suppr --project=compile_commands.json, then I got the following result:

Checking a.cpp ...
[a.cpp:6]: (style) The function 'operator+' is never used.

Is there any documented reason why cppcheck behaves differently in the mentioned cases? If not, that it is possible that this is a bug?


Solution

  • I assume this was a bug in version 1.82, because with a newer version it is working perfectly.