Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit c521288

Browse files
committed
[clangd] IncludeCleaner: Don't consider the definition as usage for function forward declarations
Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D111711
1 parent 7812f51 commit c521288

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang-tools-extra/clangd/IncludeCleaner.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class ReferencedLocationCrawler
3939
return true;
4040
}
4141

42+
bool VisitFunctionDecl(FunctionDecl *FD) {
43+
// Function definition will require redeclarations to be included.
44+
if (FD == FD->getDefinition())
45+
add(FD);
46+
return true;
47+
}
48+
4249
bool VisitCXXConstructExpr(CXXConstructExpr *CCE) {
4350
add(CCE->getConstructor());
4451
return true;

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ TEST(IncludeCleaner, ReferencedLocations) {
7979
"struct ^X { ^X(int) {} int ^foo(); };",
8080
"auto x = X(42); auto y = x.foo();",
8181
},
82+
// Function
83+
{
84+
"void ^foo();",
85+
"void foo() {}",
86+
},
87+
{
88+
"void foo() {}",
89+
"void foo();",
90+
},
91+
{
92+
"inline void ^foo() {}",
93+
"void bar() { foo(); }",
94+
},
8295
// Static function
8396
{
8497
"struct ^X { static bool ^foo(); }; bool X::^foo() {}",

0 commit comments

Comments
 (0)