Skip to content

Commit

Permalink
[clangd] Extend findTarget()'s dependent name heuristic to handle enu…
Browse files Browse the repository at this point in the history
…merators

Fixes clangd/clangd#296

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76103
  • Loading branch information
HighCommander4 committed Mar 17, 2020
1 parent a2920c4 commit 31b7f0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang-tools-extra/clangd/FindTarget.cpp
Expand Up @@ -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>

Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/clangd/unittests/XRefsTests.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 31b7f0e

Please sign in to comment.