I use an open source library VTK which has multiline macros (in vtkSetGet.h) containing static_cast statements that our clang-tidy configuration warns about. I tried to suppress these warnings by surrounding them with NOLINT comments like this:
...
/*NOLINTBEGIN(cppcoreguidelines-pro-type-static-cast-downcast)*/ \
return static_cast<thisClass*>(o); \
/*NOLINTEND(cppcoreguidelines-pro-type-static-cast-downcast)*/ \
...
But this doesn’t seem to work: I still see the calls being flagged.
Can someone advise me on how to suppress these warnings?
You should not need to touch any of the VTK code. Instead, make sure that it is included as a “system library”, i.e. that the include directory is of the form -isystem /path/to/vtk/include
Can I do that in a .clang-tidy file too? What would be the syntax for that?
You can try to play with the HeaderFilterRegex
option as well, but I haven’t found this very useful in practice. My solution above has to do with your build system.
Anyhow, if you do want to touch VTK code, it should be something like:
// NOLINTBEGIN(cppcoreguidelines-pro-type-static-cast-downcast)
#define MULTILINE_MACRO \
... \
... \
...
// NOLINTEND(cppcoreguidelines-pro-type-static-cast-downcast)
I’ve tried this and also around the entire contents of the header file, but nothing seems to work …
Strange, this works:
/// NOLINTBEGIN(*explicit*)
#define MY_MACRO \
struct X \
{ \
X(int) \
{} \
};
/// NOLINTEND(*explicit*)
MY_MACRO