[clang-tidy] Fix a heap use-after-free bug detected by asan.
llvm-svn: 213845
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp
index f1d9042..1aabf6a 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp
@@ -17,7 +17,7 @@
namespace ast_matchers {
AST_MATCHER(CXXRecordDecl, hasUserDeclaredDestructor) {
// TODO: If the dtor is there but empty we don't want to warn either.
- return Node.hasUserDeclaredDestructor();
+ return Node.hasDefinition() && Node.hasUserDeclaredDestructor();
}
} // namespace ast_matchers
@@ -73,9 +73,9 @@
// Otherwise just suggest adding a name. To find the place to insert the name
// find the first TypeLoc in the children of E, which always points to the
// written type.
- const auto *TL =
- selectFirst<TypeLoc>("t", match(expr(hasDescendant(typeLoc().bind("t"))),
- *E, *Result.Context));
+ auto Matches =
+ match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
+ const auto *TL = selectFirst<TypeLoc>("t", Matches);
D << FixItHint::CreateInsertion(
Lexer::getLocForEndOfToken(TL->getLocEnd(), 0, *Result.SourceManager,
Result.Context->getLangOpts()),