[clang-tools-extra] r246310 - 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.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 28 10:58:11 PDT 2015
Author: aaronballman
Date: Fri Aug 28 12:58:10 2015
New Revision: 246310
URL: http://llvm.org/viewvc/llvm-project?rev=246310&view=rev
Log:
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.
Added:
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert.c
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=246310&r1=246309&r2=246310&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Fri Aug 28 12:58:10 2015
@@ -539,9 +539,14 @@ void LoopConvertCheck::findAndVerifyUsag
}
void LoopConvertCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(makeArrayLoopMatcher(), this);
- Finder->addMatcher(makeIteratorLoopMatcher(), this);
- Finder->addMatcher(makePseudoArrayLoopMatcher(), this);
+ // Only register the matchers for C++. Because this checker is used for
+ // modernization, it is reasonable to run it on any C++ standard with the
+ // assumption the user is trying to modernize their codebase.
+ if (getLangOpts().CPlusPlus) {
+ Finder->addMatcher(makeArrayLoopMatcher(), this);
+ Finder->addMatcher(makeIteratorLoopMatcher(), this);
+ Finder->addMatcher(makePseudoArrayLoopMatcher(), this);
+ }
}
void LoopConvertCheck::check(const MatchFinder::MatchResult &Result) {
Modified: clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp?rev=246310&r1=246309&r2=246310&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp Fri Aug 28 12:58:10 2015
@@ -127,35 +127,46 @@ void PassByValueCheck::storeOptions(Clan
}
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) {
Modified: clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp?rev=246310&r1=246309&r2=246310&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp Fri Aug 28 12:58:10 2015
@@ -198,15 +198,24 @@ void ReplaceAutoPtrCheck::storeOptions(C
}
void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(makeAutoPtrTypeLocMatcher(), this);
- Finder->addMatcher(makeAutoPtrUsingDeclMatcher(), this);
- Finder->addMatcher(makeTransferOwnershipExprMatcher(), 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(makeAutoPtrTypeLocMatcher(), this);
+ Finder->addMatcher(makeAutoPtrUsingDeclMatcher(), this);
+ Finder->addMatcher(makeTransferOwnershipExprMatcher(), this);
+ }
}
void ReplaceAutoPtrCheck::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 ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=246310&r1=246309&r2=246310&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Fri Aug 28 12:58:10 2015
@@ -238,8 +238,12 @@ StatementMatcher makeDeclWithNewMatcher(
} // namespace
void UseAutoCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(makeIteratorDeclMatcher(), this);
- Finder->addMatcher(makeDeclWithNewMatcher(), 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(makeIteratorDeclMatcher(), this);
+ Finder->addMatcher(makeDeclWithNewMatcher(), this);
+ }
}
void UseAutoCheck::replaceIterators(const DeclStmt *D, ASTContext *Context) {
Added: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert.c?rev=246310&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert.c (added)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert.c Fri Aug 28 12:58:10 2015
@@ -0,0 +1,12 @@
+// RUN: clang-tidy %s -checks=-*,modernize-loop-convert -- -std=c11 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+int arr[6] = {1, 2, 3, 4, 5, 6};
+
+void f(void) {
+ for (int i = 0; i < 6; ++i) {
+ (void)arr[i];
+ }
+}
More information about the cfe-commits
mailing list