diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -63,6 +63,21 @@ return true; } + bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) { + QualType Type = E->getBaseType().getCanonicalType(); + if (Type->isPointerType()) { + Type = Type->getPointeeType(); + } + + if (isa(Type)) { + const TemplateSpecializationType *TST = + cast(Type); + TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl(); + report(E->getMemberLoc(), TD); + } + return true; + } + bool VisitCXXConstructExpr(CXXConstructExpr *E) { report(E->getLocation(), E->getConstructor(), E->getParenOrBraceRange().isValid() ? RefType::Explicit diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -88,12 +88,10 @@ auto RTStr = llvm::to_string(RT); for (auto Expected : Target.points(RTStr)) if (!llvm::is_contained(ReferencedOffsets[RT], Expected)) - DiagnosePoint("location not marked used with type " + RTStr, - Expected); + DiagnosePoint("location not marked used with type " + RTStr, Expected); for (auto Actual : ReferencedOffsets[RT]) if (!llvm::is_contained(Target.points(RTStr), Actual)) - DiagnosePoint("location unexpectedly used with type " + RTStr, - Actual); + DiagnosePoint("location unexpectedly used with type " + RTStr, Actual); } // If there were any differences, we print the entire referencing code once. @@ -178,6 +176,15 @@ "void foo() { X{}.^foo(); }"); } +TEST(WalkAST, CXXDependentScopeMemberExprs) { + testWalk("template struct $explicit^Base { void method(); };", + "template void k(Base t) { t.^method(); }"); + testWalk("template struct $explicit^Base { void method(); };", + "template void k(Base& t) { t.^method(); }"); + testWalk("template struct $explicit^Base { void method(); };", + "template void k(Base* t) { t->^method(); }"); +} + TEST(WalkAST, ConstructExprs) { testWalk("struct $implicit^S {};", "S ^t;"); testWalk("struct S { $implicit^S(); };", "S ^t;");