From 4ff1ffa1cec5b168f65e07319c411aeaf179c44a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 23 Jul 2014 11:50:54 +0000 Subject: [PATCH] Add the fix that should've accompanied r213738. llvm-svn: 213740 --- clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp | 9 ++++++--- 1 file 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 7f06a49..f1d9042 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"); + // 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("t", match(expr(hasDescendant(typeLoc().bind("t"))), + *E, *Result.Context)); D << FixItHint::CreateInsertion( Lexer::getLocForEndOfToken(TL->getLocEnd(), 0, *Result.SourceManager, Result.Context->getLangOpts()), -- 2.7.4