[clangd] IncludeCleaner: Mark possible expr resolutions as used
authorKirill Bobyrev <kbobyrev@google.com>
Mon, 22 Nov 2021 09:44:21 +0000 (10:44 +0100)
committerKirill Bobyrev <kbobyrev@google.com>
Mon, 22 Nov 2021 09:44:24 +0000 (10:44 +0100)
Fixes: https://github.com/clangd/clangd/issues/934

Reviewed By: sammccall

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

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

index eb593ad..b9267ff 100644 (file)
@@ -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 @@ public:
     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>;
 
index 404be5e..f25f738 100644 (file)
@@ -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() {}",