[clang-tools-extra] r309810 - Adapt clang-tidy checks to changing semantics of hasDeclaration.
Manuel Klimek via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 2 06:13:11 PDT 2017
Author: klimek
Date: Wed Aug 2 06:13:11 2017
New Revision: 309810
URL: http://llvm.org/viewvc/llvm-project?rev=309810&view=rev
Log:
Adapt clang-tidy checks to changing semantics of hasDeclaration.
Differential Revision: https://reviews.llvm.org/D36154
Modified:
clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
Modified: clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp Wed Aug 2 06:13:11 2017
@@ -27,8 +27,8 @@ void StringReferenceMemberCheck::registe
return;
// Look for const references to std::string or ::string.
- auto String = anyOf(recordDecl(hasName("::std::basic_string")),
- recordDecl(hasName("::string")));
+ auto String = anyOf(namedDecl(hasName("::std::string")),
+ namedDecl(hasName("::string")));
auto ConstString = qualType(isConstQualified(), hasDeclaration(String));
// Ignore members in template instantiations.
Modified: clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp Wed Aug 2 06:13:11 2017
@@ -71,11 +71,13 @@ ast_matchers::internal::BindableMatcher<
// For sequences: assign, push_back, resize.
cxxMemberCallExpr(
callee(functionDecl(hasAnyName("assign", "push_back", "resize"))),
- on(expr(hasType(recordDecl(isASequence()))))),
+ on(expr(hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(recordDecl(isASequence())))))))),
// For sequences and sets: insert.
- cxxMemberCallExpr(
- callee(functionDecl(hasName("insert"))),
- on(expr(hasType(recordDecl(anyOf(isASequence(), isASet())))))),
+ cxxMemberCallExpr(callee(functionDecl(hasName("insert"))),
+ on(expr(hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(recordDecl(
+ anyOf(isASequence(), isASet()))))))))),
// For maps: operator[].
cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(isAMap()))),
hasOverloadedOperatorName("[]"))));
@@ -103,7 +105,8 @@ void DanglingHandleCheck::registerMatche
// Find 'Handle foo(ReturnsAValue());'
Finder->addMatcher(
- varDecl(hasType(cxxRecordDecl(IsAHandle)),
+ varDecl(hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(IsAHandle))))),
hasInitializer(
exprWithCleanups(has(ignoringParenImpCasts(ConvertedHandle)))
.bind("bad_stmt"))),
@@ -112,7 +115,9 @@ void DanglingHandleCheck::registerMatche
// Find 'Handle foo = ReturnsAValue();'
Finder->addMatcher(
varDecl(
- hasType(cxxRecordDecl(IsAHandle)), unless(parmVarDecl()),
+ hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(IsAHandle))))),
+ unless(parmVarDecl()),
hasInitializer(exprWithCleanups(has(ignoringParenImpCasts(handleFrom(
IsAHandle, ConvertedHandle))))
.bind("bad_stmt"))),
@@ -139,13 +144,15 @@ void DanglingHandleCheck::registerMatche
// We have to match both.
has(ignoringImplicit(handleFrom(
IsAHandle,
- handleFrom(IsAHandle, declRefExpr(to(varDecl(
- // Is function scope ...
- hasAutomaticStorageDuration(),
- // ... and it is a local array or Value.
- anyOf(hasType(arrayType()),
- hasType(recordDecl(
- unless(IsAHandle))))))))))),
+ handleFrom(IsAHandle,
+ declRefExpr(to(varDecl(
+ // Is function scope ...
+ hasAutomaticStorageDuration(),
+ // ... and it is a local array or Value.
+ anyOf(hasType(arrayType()),
+ hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(recordDecl(
+ unless(IsAHandle)))))))))))))),
// Temporary fix for false positives inside lambdas.
unless(hasAncestor(lambdaExpr())))
.bind("bad_stmt"),
Modified: clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp Wed Aug 2 06:13:11 2017
@@ -39,7 +39,8 @@ void InaccurateEraseCheck::registerMatch
anything())))
.bind("alg");
- const auto DeclInStd = decl(isInStdNamespace());
+ const auto DeclInStd = type(hasUnqualifiedDesugaredType(
+ tagType(hasDeclaration(decl(isInStdNamespace())))));
Finder->addMatcher(
cxxMemberCallExpr(
on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd)))),
Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Wed Aug 2 06:13:11 2017
@@ -271,15 +271,17 @@ void UseAfterMoveFinder::getReinits(
auto DeclRefMatcher =
declRefExpr(hasDeclaration(equalsNode(MovedVariable))).bind("declref");
- auto StandardContainerTypeMatcher = hasType(cxxRecordDecl(
- hasAnyName("::std::basic_string", "::std::vector", "::std::deque",
- "::std::forward_list", "::std::list", "::std::set",
- "::std::map", "::std::multiset", "::std::multimap",
- "::std::unordered_set", "::std::unordered_map",
- "::std::unordered_multiset", "::std::unordered_multimap")));
+ auto StandardContainerTypeMatcher = hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
+ "::std::basic_string", "::std::vector", "::std::deque",
+ "::std::forward_list", "::std::list", "::std::set", "::std::map",
+ "::std::multiset", "::std::multimap", "::std::unordered_set",
+ "::std::unordered_map", "::std::unordered_multiset",
+ "::std::unordered_multimap"))))));
- auto StandardSmartPointerTypeMatcher = hasType(cxxRecordDecl(
- hasAnyName("::std::unique_ptr", "::std::shared_ptr", "::std::weak_ptr")));
+ auto StandardSmartPointerTypeMatcher = hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
+ "::std::unique_ptr", "::std::shared_ptr", "::std::weak_ptr"))))));
// Matches different types of reinitialization.
auto ReinitMatcher =
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=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Wed Aug 2 06:13:11 2017
@@ -161,17 +161,18 @@ StatementMatcher makeIteratorLoopMatcher
// overloaded operator*(). If the operator*() returns by value instead of by
// reference then the return type is tagged with DerefByValueResultName.
internal::Matcher<VarDecl> TestDerefReturnsByValue =
- hasType(cxxRecordDecl(hasMethod(allOf(
- hasOverloadedOperatorName("*"),
- anyOf(
- // Tag the return type if it's by value.
- returns(qualType(unless(hasCanonicalType(referenceType())))
- .bind(DerefByValueResultName)),
- returns(
- // Skip loops where the iterator's operator* returns an
- // rvalue reference. This is just weird.
- qualType(unless(hasCanonicalType(rValueReferenceType())))
- .bind(DerefByRefResultName)))))));
+ hasType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(hasMethod(allOf(
+ hasOverloadedOperatorName("*"),
+ anyOf(
+ // Tag the return type if it's by value.
+ returns(qualType(unless(hasCanonicalType(referenceType())))
+ .bind(DerefByValueResultName)),
+ returns(
+ // Skip loops where the iterator's operator* returns an
+ // rvalue reference. This is just weird.
+ qualType(unless(hasCanonicalType(rValueReferenceType())))
+ .bind(DerefByRefResultName))))))))));
return forStmt(
unless(isInTemplateInstantiation()),
@@ -242,16 +243,17 @@ StatementMatcher makePseudoArrayLoopMatc
// functions called begin() and end() taking the container as an argument
// are also allowed.
TypeMatcher RecordWithBeginEnd = qualType(anyOf(
- qualType(isConstQualified(),
- hasDeclaration(cxxRecordDecl(
- hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
- hasMethod(cxxMethodDecl(hasName("end"),
- isConst())))) // hasDeclaration
- ), // qualType
qualType(
- unless(isConstQualified()),
- hasDeclaration(cxxRecordDecl(hasMethod(hasName("begin")),
- hasMethod(hasName("end"))))) // qualType
+ isConstQualified(),
+ hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
+ hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
+ hasMethod(cxxMethodDecl(hasName("end"),
+ isConst())))) // hasDeclaration
+ ))), // qualType
+ qualType(unless(isConstQualified()),
+ hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasMethod(hasName("begin")),
+ hasMethod(hasName("end"))))))) // qualType
));
StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp Wed Aug 2 06:13:11 2017
@@ -20,10 +20,11 @@ MakeSharedCheck::MakeSharedCheck(StringR
MakeSharedCheck::SmartPtrTypeMatcher
MakeSharedCheck::getSmartPointerTypeMatcher() const {
- return qualType(hasDeclaration(classTemplateSpecializationDecl(
- hasName("::std::shared_ptr"), templateArgumentCountIs(1),
- hasTemplateArgument(
- 0, templateArgument(refersToType(qualType().bind(PointerType)))))));
+ return qualType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(classTemplateSpecializationDecl(
+ hasName("::std::shared_ptr"), templateArgumentCountIs(1),
+ hasTemplateArgument(0, templateArgument(refersToType(
+ qualType().bind(PointerType)))))))));
}
} // namespace modernize
Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp Wed Aug 2 06:13:11 2017
@@ -21,18 +21,19 @@ MakeUniqueCheck::MakeUniqueCheck(StringR
MakeUniqueCheck::SmartPtrTypeMatcher
MakeUniqueCheck::getSmartPointerTypeMatcher() const {
- return qualType(hasDeclaration(classTemplateSpecializationDecl(
- hasName("::std::unique_ptr"), templateArgumentCountIs(2),
- hasTemplateArgument(
- 0, templateArgument(refersToType(qualType().bind(PointerType)))),
- hasTemplateArgument(
- 1,
- templateArgument(refersToType(
- qualType(hasDeclaration(classTemplateSpecializationDecl(
- hasName("::std::default_delete"), templateArgumentCountIs(1),
- hasTemplateArgument(
- 0, templateArgument(refersToType(
- qualType(equalsBoundNode(PointerType))))))))))))));
+ return qualType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(classTemplateSpecializationDecl(
+ hasName("::std::unique_ptr"), templateArgumentCountIs(2),
+ hasTemplateArgument(
+ 0, templateArgument(refersToType(qualType().bind(PointerType)))),
+ hasTemplateArgument(
+ 1, templateArgument(refersToType(
+ qualType(hasDeclaration(classTemplateSpecializationDecl(
+ hasName("::std::default_delete"),
+ templateArgumentCountIs(1),
+ hasTemplateArgument(
+ 0, templateArgument(refersToType(qualType(
+ equalsBoundNode(PointerType))))))))))))))));
}
} // namespace modernize
Modified: clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp Wed Aug 2 06:13:11 2017
@@ -74,9 +74,11 @@ void FasterStringFindCheck::registerMatc
callee(functionDecl(StringFindFunctions).bind("func")),
anyOf(argumentCountIs(1), argumentCountIs(2)),
hasArgument(0, SingleChar),
- on(expr(hasType(recordDecl(hasAnyName(SmallVector<StringRef, 4>(
- StringLikeClasses.begin(), StringLikeClasses.end())))),
- unless(hasSubstitutedType())))),
+ on(expr(
+ hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ recordDecl(hasAnyName(SmallVector<StringRef, 4>(
+ StringLikeClasses.begin(), StringLikeClasses.end()))))))),
+ unless(hasSubstitutedType())))),
this);
}
Modified: clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp Wed Aug 2 06:13:11 2017
@@ -33,7 +33,8 @@ void InefficientStringConcatenationCheck
return;
const auto BasicStringType =
- hasType(cxxRecordDecl(hasName("::std::basic_string")));
+ hasType(qualType(hasUnqualifiedDesugaredType(recordType(
+ hasDeclaration(cxxRecordDecl(hasName("::std::basic_string")))))));
const auto BasicStringPlusOperator = cxxOperatorCallExpr(
hasOverloadedOperatorName("+"),
Modified: clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Wed Aug 2 06:13:11 2017
@@ -32,16 +32,18 @@ void ContainerSizeEmptyCheck::registerMa
if (!getLangOpts().CPlusPlus)
return;
- const auto ValidContainer = cxxRecordDecl(isSameOrDerivedFrom(
- namedDecl(
- has(cxxMethodDecl(
- isConst(), parameterCountIs(0), isPublic(), hasName("size"),
- returns(qualType(isInteger(), unless(booleanType()))))
- .bind("size")),
- has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
- hasName("empty"), returns(booleanType()))
- .bind("empty")))
- .bind("container")));
+ const auto ValidContainer = qualType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom(
+ namedDecl(
+ has(cxxMethodDecl(
+ isConst(), parameterCountIs(0), isPublic(),
+ hasName("size"),
+ returns(qualType(isInteger(), unless(booleanType()))))
+ .bind("size")),
+ has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
+ hasName("empty"), returns(booleanType()))
+ .bind("empty")))
+ .bind("container")))))));
const auto WrongUse = anyOf(
hasParent(binaryOperator(
Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp Wed Aug 2 06:13:11 2017
@@ -77,7 +77,8 @@ void RedundantStringCStrCheck::registerM
return;
// Match expressions of type 'string' or 'string*'.
- const auto StringDecl = cxxRecordDecl(hasName("::std::basic_string"));
+ const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
+ hasDeclaration(cxxRecordDecl(hasName("::std::basic_string"))))));
const auto StringExpr =
expr(anyOf(hasType(StringDecl), hasType(qualType(pointsTo(StringDecl)))));
Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp Wed Aug 2 06:13:11 2017
@@ -47,7 +47,8 @@ void RedundantStringInitCheck::registerM
// string bar("");
Finder->addMatcher(
namedDecl(
- varDecl(hasType(cxxRecordDecl(hasName("basic_string"))),
+ varDecl(hasType(hasUnqualifiedDesugaredType(recordType(
+ hasDeclaration(cxxRecordDecl(hasName("basic_string")))))),
hasInitializer(expr(ignoringImplicit(anyOf(
EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries)))
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp?rev=309810&r1=309809&r2=309810&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp Wed Aug 2 06:13:11 2017
@@ -230,7 +230,8 @@ void FindAllSymbols::registerMatchers(Ma
MatchFinder->addMatcher(
typeLoc(isExpansionInMainFile(),
loc(templateSpecializationType(hasDeclaration(
- classTemplateDecl(has(CXXRecords.bind("use"))))))),
+ classTemplateSpecializationDecl(hasSpecializedTemplate(
+ classTemplateDecl(has(CXXRecords.bind("use"))))))))),
this);
}
More information about the cfe-commits
mailing list