diff --git a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp index 36d979b61228..f3a7bd99209a 100644 --- a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp @@ -27,8 +27,8 @@ void StringReferenceMemberCheck::registerMatchers( 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. diff --git a/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp index 67f83d27b42b..86220f415028 100644 --- a/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp @@ -71,11 +71,13 @@ ast_matchers::internal::BindableMatcher makeContainerMatcher( // 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::registerMatchersForVariables(MatchFinder *Finder) { // 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::registerMatchersForVariables(MatchFinder *Finder) { // 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::registerMatchersForReturn(MatchFinder *Finder) { // 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"), diff --git a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp index f75d6fe8b463..fd86d1723e33 100644 --- a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp @@ -39,7 +39,8 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) { 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)))), diff --git a/clang-tools-extra/clang-tidy/misc/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseAfterMoveCheck.cpp index 842aa5b3f72a..99673766a534 100644 --- a/clang-tools-extra/clang-tidy/misc/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseAfterMoveCheck.cpp @@ -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 = diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index ac0bceb1819c..54bf941ffb2e 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -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 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 makePseudoArrayLoopMatcher() { // 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( diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp index 0495dca75030..541c2cb5af6d 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp @@ -20,10 +20,11 @@ MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context) 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 diff --git a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp index fea452f32a0c..4a9b3065e75c 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp @@ -21,18 +21,19 @@ MakeUniqueCheck::MakeUniqueCheck(StringRef Name, 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 diff --git a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp index 29dac1bc829a..eddc52b63a9a 100644 --- a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp @@ -74,9 +74,11 @@ void FasterStringFindCheck::registerMatchers(MatchFinder *Finder) { callee(functionDecl(StringFindFunctions).bind("func")), anyOf(argumentCountIs(1), argumentCountIs(2)), hasArgument(0, SingleChar), - on(expr(hasType(recordDecl(hasAnyName(SmallVector( - StringLikeClasses.begin(), StringLikeClasses.end())))), - unless(hasSubstitutedType())))), + on(expr( + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + recordDecl(hasAnyName(SmallVector( + StringLikeClasses.begin(), StringLikeClasses.end()))))))), + unless(hasSubstitutedType())))), this); } diff --git a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp index fb53167d3dd6..a17916d996a6 100644 --- a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp @@ -33,7 +33,8 @@ void InefficientStringConcatenationCheck::registerMatchers( 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("+"), diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index 24680eb629cd..5604354f15b5 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -32,16 +32,18 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) { 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( diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp index c6b384b3ac47..21f4a8a5d05b 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp @@ -77,7 +77,8 @@ void RedundantStringCStrCheck::registerMatchers( 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))))); diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp index b881e226e9cb..46ce2a47b038 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp @@ -47,7 +47,8 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { // 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))) diff --git a/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp b/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp index cf8ce4eaec5b..bd5032d04a9c 100644 --- a/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp +++ b/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp @@ -230,7 +230,8 @@ void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) { MatchFinder->addMatcher( typeLoc(isExpansionInMainFile(), loc(templateSpecializationType(hasDeclaration( - classTemplateDecl(has(CXXRecords.bind("use"))))))), + classTemplateSpecializationDecl(hasSpecializedTemplate( + classTemplateDecl(has(CXXRecords.bind("use"))))))))), this); }