diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -39,6 +39,11 @@ return true; } + bool VisitFunctionDecl(FunctionDecl *FD) { + add(FD->getDefinition()); + return true; + } + bool VisitCXXConstructExpr(CXXConstructExpr *CCE) { add(CCE->getConstructor()); return true; diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -79,6 +79,11 @@ "struct ^X { ^X(int) {} int ^foo(); };", "auto x = X(42); auto y = x.foo();", }, + // Function + { + "void ^foo();", + "void foo() {}", + }, // Static function { "struct ^X { static bool ^foo(); }; bool X::^foo() {}",