forked from OSchip/llvm-project
Adapt clang-tidy checks to changing semantics of hasDeclaration.
Differential Revision: https://reviews.llvm.org/D36154 llvm-svn: 309810
This commit is contained in:
parent
696e505278
commit
7b9c117b82
|
@ -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.
|
||||
|
|
|
@ -71,11 +71,13 @@ ast_matchers::internal::BindableMatcher<Stmt> 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"),
|
||||
|
|
|
@ -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)))),
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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 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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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("+"),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)))));
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue