[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
This commit is contained in:
Kirill Bobyrev 2021-11-22 10:44:21 +01:00
parent 760d4d03d5
commit b5f20372a8
No known key found for this signature in database
GPG Key ID: 2307C055C8384FA0
2 changed files with 12 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "SourceCode.h" #include "SourceCode.h"
#include "support/Logger.h" #include "support/Logger.h"
#include "support/Trace.h" #include "support/Trace.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceLocation.h"
#include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearch.h"
@ -104,6 +105,13 @@ public:
return true; 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: private:
using Base = RecursiveASTVisitor<ReferencedLocationCrawler>; using Base = RecursiveASTVisitor<ReferencedLocationCrawler>;

View File

@ -97,6 +97,10 @@ TEST(IncludeCleaner, ReferencedLocations) {
"inline void ^foo() {}", "inline void ^foo() {}",
"void bar() { foo(); }", "void bar() { foo(); }",
}, },
{
"int ^foo(char); int ^foo(float);",
"template<class T> int x = foo(T{});",
},
// Static function // Static function
{ {
"struct ^X { static bool ^foo(); }; bool X::^foo() {}", "struct ^X { static bool ^foo(); }; bool X::^foo() {}",