[cfe-dev] [clang-tidy] How to ignore predefined macro definitions?

Melvin Vermeeren via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 4 10:06:51 PDT 2018


Hi all,

For a portable C project using POSIX extensions I typically use a predefined 
macro, usually passing -D_POSIX_C_SOURCE=200112L or similar to the command-
line through the build system.

When also using the readability-identifier-naming checker in clang-tidy, with 
option readability-identifier-naming.MacroDefinitionCase set to UPPER_CASE, 
the following warning is emitted, due to the underscore prefix.

error: invalid case style for macro definition '_POSIX_C_SOURCE' [readability-
identifier-naming,-warnings-as-errors]

Usually /* NOLINT */ or similar can be used to silence the error, but in this 
case it it predefined, so this in not possible. It also appears that clang-
tidy's -header-filter and -line-filter cannot be used to resolve this.

Is there some other way to ignore only the _POSIX_C_SOURCE definition? Or 
perhaps some way to get it to ignore definitions passed on the command-line? 
The current "workaround" is disabling the entire readability-identifier-naming 
check, which is a shame as I find it very useful.

Version: Clang 6.0.0, Debian stretch backports, x86_64.

Thanks in advance,

Melvin Vermeeren.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181004/edcc99d0/attachment.sig>


More information about the cfe-dev mailing list