[clang-tools-extra] b5f2037 - [clangd] IncludeCleaner: Mark possible expr resolutions as used

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 22 01:44:37 PST 2021


Author: Kirill Bobyrev
Date: 2021-11-22T10:44:24+01:00
New Revision: b5f20372a82f72f03d47181b87fb55f62772324f

URL: https://github.com/llvm/llvm-project/commit/b5f20372a82f72f03d47181b87fb55f62772324f
DIFF: https://github.com/llvm/llvm-project/commit/b5f20372a82f72f03d47181b87fb55f62772324f.diff

LOG: [clangd] IncludeCleaner: Mark possible expr resolutions as used

Fixes: https://github.com/clangd/clangd/issues/934

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D114287

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp
index eb593ad86ea00..b9267ff71120d 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -13,6 +13,7 @@
 #include "SourceCode.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -104,6 +105,13 @@ class ReferencedLocationCrawler
     return true;
   }
 
+  // When the overload is not resolved yet, mark all candidates as used.
+  bool VisitOverloadExpr(OverloadExpr *E) {
+    for (const auto *ResolutionDecl : E->decls())
+      add(ResolutionDecl);
+    return true;
+  }
+
 private:
   using Base = RecursiveASTVisitor<ReferencedLocationCrawler>;
 

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 404be5e153864..f25f7388df66a 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -97,6 +97,10 @@ TEST(IncludeCleaner, ReferencedLocations) {
           "inline void ^foo() {}",
           "void bar() { foo(); }",
       },
+      {
+          "int ^foo(char); int ^foo(float);",
+          "template<class T> int x = foo(T{});",
+      },
       // Static function
       {
           "struct ^X { static bool ^foo(); }; bool X::^foo() {}",


        


More information about the cfe-commits mailing list