diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp index 9114deb5c73..64806cee37e 100644 --- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp @@ -34,7 +34,7 @@ static bool isUsedToInitializeAConstant(const MatchFinder::MatchResult &Result, return AsDecl->isImplicit(); } - if (Node.get<EnumConstantDecl>() != nullptr) + if (Node.get<EnumConstantDecl>()) return true; return llvm::any_of(Result.Context->getParents(Node), @@ -125,8 +125,20 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result, if (isUsedToInitializeAConstant(Result, Parent)) return true; - // Ignore this instance, because this match reports the location - // where the template is defined, not where it is instantiated. + // Ignore this instance, because this matches an + // expanded class enumeration value. + if (Parent.get<CStyleCastExpr>() && + llvm::any_of( + Result.Context->getParents(Parent), + [](const DynTypedNode &GrandParent) { + return GrandParent.get<SubstNonTypeTemplateParmExpr>() != + nullptr; + })) + return true; + + // Ignore this instance, because this match reports the + // location where the template is defined, not where it + // is instantiated. if (Parent.get<SubstNonTypeTemplateParmExpr>()) return true; |