[clang-tidy] Ignore macros defined within declarations
authorRichard <legalize@xmission.com>
Sun, 17 Apr 2022 00:26:01 +0000 (18:26 -0600)
committerRichard <legalize@xmission.com>
Fri, 22 Apr 2022 23:46:54 +0000 (17:46 -0600)
commitb985b6e3c15a863112e1676d6211c80c7683f3eb
tree7070c53bfa403e1352d09b0afeea099c58c1c60c
parent1af25a986069f2ae8c724133fa8649bb795a7925
[clang-tidy] Ignore macros defined within declarations

Modernize-macro-to-enum shouldn't try to convert macros to enums
when they are defined inside a declaration or definition, only
when the macros are defined at the top level.  Since preprocessing
is disconnected from AST traversal, match nodes in the AST and then
invalidate source ranges spanning AST nodes before issuing diagnostics.

ClangTidyCheck::onEndOfTranslationUnit is called before
PPCallbacks::EndOfMainFile, so defer final diagnostics to the
PPCallbacks implementation.

Differential Revision: https://reviews.llvm.org/D124066

Fixes #54883
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.h
clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp