[clangd] Extend findTarget()'s dependent name heuristic to handle enumerators

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

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76103
This commit is contained in:
Nathan Ridge 2020-03-12 18:22:44 -04:00
parent a2920c4ea9
commit 31b7f0ed6a
2 changed files with 14 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <iterator>
#include <utility>
#include <vector>
@ -76,6 +77,11 @@ std::vector<const NamedDecl *> getMembersReferencedViaDependentName(
bool IsNonstaticMember) {
if (!T)
return {};
if (auto *ET = T->getAs<EnumType>()) {
auto Result =
ET->getDecl()->lookup(NameFactory(ET->getDecl()->getASTContext()));
return {Result.begin(), Result.end()};
}
if (auto *ICNT = T->getAs<InjectedClassNameType>()) {
T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
}

View File

@ -529,6 +529,14 @@ TEST(LocateSymbol, All) {
void test(unique_ptr<S<T>>& V) {
V->fo^o();
}
)cpp",
R"cpp(// Heuristic resolution of dependent enumerator
template <typename T>
struct Foo {
enum class E { [[A]], B };
E e = E::A^;
};
)cpp"};
for (const char *Test : Tests) {
Annotations T(Test);