Skip to content

Commit

Permalink
[include-cleaner] Generate references from explicit functiontemplate …
Browse files Browse the repository at this point in the history
…specializations (#83392)
  • Loading branch information
kadircet committed Feb 29, 2024
1 parent 53bd411 commit bd595d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions clang-tools-extra/include-cleaner/lib/WalkAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
// Mark declaration from definition as it needs type-checking.
if (FD->isThisDeclarationADefinition())
report(FD->getLocation(), FD);
// Explicit specializaiton/instantiations of a function template requires
// primary template.
if (clang::isTemplateExplicitInstantiationOrSpecialization(
FD->getTemplateSpecializationKind()))
report(FD->getLocation(), FD->getPrimaryTemplate());
return true;
}
bool VisitVarDecl(VarDecl *VD) {
Expand Down
10 changes: 4 additions & 6 deletions clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,9 @@ TEST(WalkAST, FunctionTemplates) {
EXPECT_THAT(testWalk("template<typename T> void foo(T) {}",
"template void ^foo<int>(int);"),
ElementsAre());
// FIXME: Report specialized template as used from explicit specializations.
EXPECT_THAT(testWalk("template<typename T> void foo(T);",
EXPECT_THAT(testWalk("template<typename T> void $explicit^foo(T);",
"template<> void ^foo<int>(int);"),
ElementsAre());
EXPECT_THAT(testWalk("template<typename T> void foo(T) {}",
"template<typename T> void ^foo(T*) {}"),
ElementsAre());
ElementsAre(Decl::FunctionTemplate));

// Implicit instantiations references most relevant template.
EXPECT_THAT(testWalk(R"cpp(
Expand Down Expand Up @@ -510,6 +506,8 @@ TEST(WalkAST, Functions) {
// Definition uses declaration, not the other way around.
testWalk("void $explicit^foo();", "void ^foo() {}");
testWalk("void foo() {}", "void ^foo();");
testWalk("template <typename> void $explicit^foo();",
"template <typename> void ^foo() {}");

// Unresolved calls marks all the overloads.
testWalk("void $ambiguous^foo(int); void $ambiguous^foo(char);",
Expand Down

0 comments on commit bd595d5

Please sign in to comment.