diff options
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp index 7f06a49f5f8..f1d90425108 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp @@ -34,7 +34,6 @@ void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) { anyOf(recordDecl(ast_matchers::isTemplateInstantiation()), functionDecl(ast_matchers::isTemplateInstantiation()))))), hasParent(compoundStmt().bind("compound")), - hasDescendant(typeLoc().bind("typeloc")), hasType(recordDecl(hasUserDeclaredDestructor())), anyOf(has(BindTemp), has(functionalCastExpr(has(BindTemp))))) .bind("expr"), @@ -71,8 +70,12 @@ void UnusedRAIICheck::check(const MatchFinder::MatchResult &Result) { return; } - // Otherwise just suggest adding a name. - const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("typeloc"); + // 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)); D << FixItHint::CreateInsertion( Lexer::getLocForEndOfToken(TL->getLocEnd(), 0, *Result.SourceManager, Result.Context->getLangOpts()), |