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

Roman Lebedev via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 4 10:35:31 PDT 2018


On Thu, Oct 4, 2018 at 8:07 PM Melvin Vermeeren via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> 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]
Just a thought:
https://clang.llvm.org/doxygen/SourceLocation_8h_source.html#l00108
clang::SourceLocation::isValid()
103  /// Return true if this is a valid SourceLocation object.
104  ///
105  /// Invalid SourceLocations are often used when events have no
corresponding
106  /// location in the source (e.g. a diagnostic is required for a
command line
107  /// option).
^ is that not being checked/honored before emitting the diagnostic?

> 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.
Roman.

>_______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list