Built-in way to disable clang-tidy validation

I am trying to configure clang-tidy for a project. I would like to have clean output and encourage the use of -fix mode where possible. However, there are some cases where an exception is required.

How can i use

#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreserved-id-macro" // Code that is being specially exempted #pragma clang diagnostic pop 

for the equivalent case where you need to disable the compiler warning locally, is it possible to do something like this from clang-tidy?

I tried

 #pragma clang diagnostic push #pragma clang diagnostic ignored "readability-identifier-naming" // Code that is being specially exempted #pragma clang diagnostic pop 

as well as replacing clang with clang-tidy . Unfortunately, when using clang as the target of a pragma and compiling using regular clang, I get a compilation warning

 warning: pragma diagnostic expected option name (eg "-Wundef") [-Wunknown-pragmas] 

and

 warning: unknown pragma ignored [clang-diagnostic-unknown-pragmas] 

when compiling, if I use clang-tidy instead of clang . It does not affect what clang-tidy displays when run through the source.

This is with clang and clang-tidy 3.8 on x86_64 Linux.

+10
c ++ clang ++ clang-tidy
source share
1 answer

Just add a comment containing the NOLINT line anywhere in the line you want to ignore. For example:

 badcode; // NOLINT // NOLINTNEXTLINE badcode; badcode; // NOLINT(cert-err-58-cpp) 

See the documentation here .

+15
source share

All Articles