Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to set up clang-tidy for a project. I'd like to be able to have clean output, and encourage the use of -fix mode where possible. However, there are individual cases where an exception is needed.

Much as it is possible to 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 one wants to locally disable a compiler warning, is it possible to do something similar from clang-tidy?

I have tried

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

and also with clang replaced with clang-tidy. Unfortunately when using clang as the pragma target and compiling with regular clang, I get the compilation warning

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

and

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

when compiling if I use clang-tidy in place of clang. Neither make an impact on what clang-tidy itself outputs when run over the source.

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

question from:https://stackoverflow.com/questions/37950439/inline-way-to-disable-clang-tidy-checks

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
619 views
Welcome To Ask or Share your Answers For Others

1 Answer

Just add a comment containing the string NOLINT anywhere on the line you want clang-tidy to ignore. For example:

badcode;  // NOLINT

// NOLINTNEXTLINE
badcode;

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

See the documentation here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...