[PATCH] D90835: [RFC][clang-tidy] Ignore diagnostics due to macro expansion from not-interested headers

Dmitry Polukhin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 03:23:40 PST 2020


DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: alexfh, njames93, thakis.
DmitryPolukhin added projects: clang, clang-tools-extra.
Herald added subscribers: kbarton, xazax.hun, nemanjai.
DmitryPolukhin requested review of this revision.

This diff is an attempt to workaround a common problem with clang-tidy deployment.
There are headers that might not be compatible with your project style guide but you
have to use macro from that headers so clang-tidy could report lots of style issues
that you cannot fix or is some cases even annotate with NOLINT. Solution proposed
in this diff is to avoid reporting diagnostics in macro expansion of the macro defined
in headers that doesn't match the desired `--header-filter`.

Just one real life example of this issue from a very popular gflags library.
This library requires using macro in use code like this:

  DEFINE_bool(some_bool_flag,
              "the default value should go here, not the description",
              false);

But the macro has outdated version of compiler assert that uses C-style arrays <https://github.com/gflags/gflags/blob/2e227c3daae2ea8899f49858a23f3d318ea39b57/src/gflags.h.in#L528>.
Therefore use code becomes incompatible with clang-tidy check `modernize-avoid-c-arrays`.
Another example of problematic is googletest/googlemock with lots of macro that you cannot avoid.

This diff implements new behavior by default but it might be also possible to
enable it behind some configuration flag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90835

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/macros.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/macros.h
  clang-tools-extra/test/clang-tidy/infrastructure/macros_filter.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90835.303070.patch
Type: text/x-patch
Size: 9255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201105/22a30c84/attachment.bin>


More information about the cfe-commits mailing list