summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy
diff options
context:
space:
mode:
authorFlorin Iucha <florin@signbit.net>2019-12-24 10:03:00 -0500
committerAaron Ballman <aaron@aaronballman.com>2019-12-24 10:03:00 -0500
commitc16b3ec597d277b5a7397db308f8ec730f3330a3 (patch)
treeb120c0bdfda3f2714ef48071735821241a1831e3 /clang-tools-extra/clang-tidy
parentdf5c2159d0a8a6d025504779f96e58e393b44c1f (diff)
downloadbcm5719-llvm-c16b3ec597d277b5a7397db308f8ec730f3330a3.tar.gz
bcm5719-llvm-c16b3ec597d277b5a7397db308f8ec730f3330a3.zip
Fix false positive in magic number checker.
cppcoreguidelines-avoid-magic-numbers should not warn about enum class. Fixes PR40640.
Diffstat (limited to 'clang-tools-extra/clang-tidy')
-rw-r--r--clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp18
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;
OpenPOWER on IntegriCloud