Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude single checks from clang-tidy file?

Tags:

c++

clang-tidy

Let's talk about this simple example:

#include <iostream>

int main(int argc, char *argv[])
{
  std::cout << "started " << argv[0] << " with " << argc << " params." << std::endl;
  return 0;
}

We have a minimal .clang-tidy file which looks like this:

Checks:
    '-*,
    cppcoreguidelines-*,
    -cppcoreguidelines-pro-bounds-pointer-arithmetic'

WarningsAsErrors:
    '*'

Even though I get the following warning:

src/main.cpp:5:30: error: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic,-warnings-as-errors]
  std::cout << "started " << argv[0] << " with " << argc << " params." << std::endl;
                             ^

I don't want to mess around with NOLINT in my code and I don't want to add some additional flags to the CMakeLists.txt file just because of clang-tidy.

Is there a clean way, to mask some single checks in the .clang-tidy file?

I'm using gcc/g++ and clang-tidy in version 6.0.0 on Linux. I'm aware of How to disable a clang-tidy check? - but it doesn't answer my question and the duplicate link is simply wrong.

like image 317
Charly Avatar asked Oct 15 '25 07:10

Charly


1 Answers

In my case, I think the problem had to do with glob expansion order. Originally, the Checks line in my .clang-tidy looked like this:

Checks: 'clang-diagnostic-*,clang-analyzer-*,*'

I wanted to disable the altera-unroll-loops diagnostic. The fix was to add it after that sneaky glob-all at the end:

Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-altera-unroll-loops'

Initially, I had it placed before the *, which, I think, caused it to be overridden. I also had no problem with it being split across multiple lines, like you have above.

like image 135
edtwardy Avatar answered Oct 18 '25 02:10

edtwardy