summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-08-28 17:58:10 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-08-28 17:58:10 +0000
commit8b0583ef1be53849546f76f8dcb60c031c64abb3 (patch)
treebd2e4cb393fd5410219ac0ecda8cf16556b3a924 /clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
parent28e2b717fc42a9282e56ab58c349b13108fc70e0 (diff)
downloadbcm5719-llvm-8b0583ef1be53849546f76f8dcb60c031c64abb3.tar.gz
bcm5719-llvm-8b0583ef1be53849546f76f8dcb60c031c64abb3.zip
Disable several more clang-tidy modernize checkers when not compiling in C++ mode. Loop conversion would make recommendations for C code, so added a test to ensure that does not happen. The pass by value, use auto and replace auto_ptr checkers would not make recommendations for C code, and are disabled for performance reasons, but do not require an extra test.
llvm-svn: 246310
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp63
1 files changed, 37 insertions, 26 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index d039e0111e0..0cbb606d09a 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -127,35 +127,46 @@ void PassByValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- constructorDecl(
- forEachConstructorInitializer(
- ctorInitializer(
- // Clang builds a CXXConstructExpr only whin it knows which
- // constructor will be called. In dependent contexts a
- // ParenListExpr is generated instead of a CXXConstructExpr,
- // filtering out templates automatically for us.
- withInitializer(constructExpr(
- has(declRefExpr(to(
- parmVarDecl(
- hasType(qualType(
- // Match only const-ref or a non-const value
- // parameters. Rvalues and const-values
- // shouldn't be modified.
- anyOf(constRefType(), nonConstValueType()))))
- .bind("Param")))),
- hasDeclaration(constructorDecl(
- isCopyConstructor(), unless(isDeleted()),
- hasDeclContext(recordDecl(isMoveConstructible())))))))
- .bind("Initializer")))
- .bind("Ctor"),
- this);
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (getLangOpts().CPlusPlus) {
+ Finder->addMatcher(
+ constructorDecl(
+ forEachConstructorInitializer(
+ ctorInitializer(
+ // Clang builds a CXXConstructExpr only whin it knows which
+ // constructor will be called. In dependent contexts a
+ // ParenListExpr is generated instead of a CXXConstructExpr,
+ // filtering out templates automatically for us.
+ withInitializer(constructExpr(
+ has(declRefExpr(to(
+ parmVarDecl(
+ hasType(qualType(
+ // Match only const-ref or a non-const value
+ // parameters. Rvalues and const-values
+ // shouldn't be modified.
+ anyOf(constRefType(),
+ nonConstValueType()))))
+ .bind("Param")))),
+ hasDeclaration(constructorDecl(
+ isCopyConstructor(), unless(isDeleted()),
+ hasDeclContext(
+ recordDecl(isMoveConstructible())))))))
+ .bind("Initializer")))
+ .bind("Ctor"),
+ this);
+ }
}
void PassByValueCheck::registerPPCallbacks(CompilerInstance &Compiler) {
- Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
- Compiler.getLangOpts(), IncludeStyle));
- Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+ // Only register the preprocessor callbacks for C++; the functionality
+ // currently does not provide any benefit to other languages, despite being
+ // benign.
+ if (getLangOpts().CPlusPlus) {
+ Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
+ Compiler.getLangOpts(), IncludeStyle));
+ Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+ }
}
void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
OpenPOWER on IntegriCloud