summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-08-28 19:27:19 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-08-28 19:27:19 +0000
commit327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c (patch)
tree787f0b09c43bf1d18e7b891e8f6d33cd4bbc5956 /clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp
parentff7da34bc36d2859076876637ad2b04796cbb81c (diff)
downloadbcm5719-llvm-327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c.tar.gz
bcm5719-llvm-327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c.zip
Disable clang-tidy misc checkers when not compiling in C++ mode. Many of the checkers do not require additional testing as the tests will not compile for other languages or modes, or the checkers would never match a valid construct.
llvm-svn: 246318
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp53
1 files changed, 29 insertions, 24 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp
index 3ca6c8196d7..17ef560227f 100644
--- a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp
@@ -28,30 +28,35 @@ static bool areTypesCompatible(QualType Left, QualType Right) {
}
void InefficientAlgorithmCheck::registerMatchers(MatchFinder *Finder) {
- const std::string Algorithms =
- "^::std::(find|count|equal_range|lower_bound|upper_bound)$";
- const auto ContainerMatcher = classTemplateSpecializationDecl(
- matchesName("^::std::(unordered_)?(multi)?(set|map)$"));
- const auto Matcher =
- callExpr(
- callee(functionDecl(matchesName(Algorithms))),
- hasArgument(
- 0, constructExpr(has(memberCallExpr(
- callee(methodDecl(hasName("begin"))),
- on(declRefExpr(
- hasDeclaration(decl().bind("IneffContObj")),
- anyOf(hasType(ContainerMatcher.bind("IneffCont")),
- hasType(pointsTo(
- ContainerMatcher.bind("IneffContPtr")))))
- .bind("IneffContExpr")))))),
- hasArgument(1, constructExpr(has(memberCallExpr(
- callee(methodDecl(hasName("end"))),
- on(declRefExpr(hasDeclaration(
- equalsBoundNode("IneffContObj")))))))),
- hasArgument(2, expr().bind("AlgParam")),
- unless(isInTemplateInstantiation())).bind("IneffAlg");
-
- Finder->addMatcher(Matcher, this);
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (getLangOpts().CPlusPlus) {
+ const std::string Algorithms =
+ "^::std::(find|count|equal_range|lower_bound|upper_bound)$";
+ const auto ContainerMatcher = classTemplateSpecializationDecl(
+ matchesName("^::std::(unordered_)?(multi)?(set|map)$"));
+ const auto Matcher =
+ callExpr(
+ callee(functionDecl(matchesName(Algorithms))),
+ hasArgument(
+ 0, constructExpr(has(memberCallExpr(
+ callee(methodDecl(hasName("begin"))),
+ on(declRefExpr(
+ hasDeclaration(decl().bind("IneffContObj")),
+ anyOf(hasType(ContainerMatcher.bind("IneffCont")),
+ hasType(pointsTo(ContainerMatcher.bind(
+ "IneffContPtr")))))
+ .bind("IneffContExpr")))))),
+ hasArgument(1, constructExpr(has(memberCallExpr(
+ callee(methodDecl(hasName("end"))),
+ on(declRefExpr(hasDeclaration(
+ equalsBoundNode("IneffContObj")))))))),
+ hasArgument(2, expr().bind("AlgParam")),
+ unless(isInTemplateInstantiation()))
+ .bind("IneffAlg");
+
+ Finder->addMatcher(Matcher, this);
+ }
}
void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
OpenPOWER on IntegriCloud