summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp
index 67f83d27b42..86220f41502 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<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"),
OpenPOWER on IntegriCloud