[PATCH] D111711: [clangd] IncludeCleaner: Don't consider the definition as usage for function forward declarations

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 26 01:37:38 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc521288ed391: [clangd] IncludeCleaner: Don't consider the definition as usage for function… (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111711/new/

https://reviews.llvm.org/D111711

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -79,6 +79,19 @@
           "struct ^X { ^X(int) {} int ^foo(); };",
           "auto x = X(42); auto y = x.foo();",
       },
+      // Function
+      {
+          "void ^foo();",
+          "void foo() {}",
+      },
+      {
+          "void foo() {}",
+          "void foo();",
+      },
+      {
+          "inline void ^foo() {}",
+          "void bar() { foo(); }",
+      },
       // Static function
       {
           "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -39,6 +39,13 @@
     return true;
   }
 
+  bool VisitFunctionDecl(FunctionDecl *FD) {
+    // Function definition will require redeclarations to be included.
+    if (FD == FD->getDefinition())
+      add(FD);
+    return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *CCE) {
     add(CCE->getConstructor());
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111711.382222.patch
Type: text/x-patch
Size: 1308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211026/be2c1bc5/attachment-0001.bin>


More information about the cfe-commits mailing list