[PATCH] D69624: [clangd] Fix namespace aliases in findExplicitReferences
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 30 09:53:01 PDT 2019
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69624
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -882,6 +882,28 @@
"0: targets = {x}, decl\n"
"1: targets = {fptr}, decl\n"
"2: targets = {a}, decl\n"},
+ // Namespace aliases should be handled properly.
+ {
+ R"cpp(
+ namespace ns { struct Type {} }
+ namespace alias = ns;
+ namespace rec_alias = alias;
+
+ void foo() {
+ $0^ns::$1^Type $2^a;
+ $3^alias::$4^Type $5^b;
+ $6^rec_alias::$7^Type $8^c;
+ }
+ )cpp",
+ "0: targets = {ns}\n"
+ "1: targets = {ns::Type}, qualifier = 'ns::'\n"
+ "2: targets = {a}, decl\n"
+ "3: targets = {alias}\n"
+ "4: targets = {ns::Type}, qualifier = 'alias::'\n"
+ "5: targets = {b}, decl\n"
+ "6: targets = {rec_alias}\n"
+ "7: targets = {ns::Type}, qualifier = 'rec_alias::'\n"
+ "8: targets = {c}, decl\n"},
};
for (const auto &C : Cases) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -674,10 +674,14 @@
return refInDecl(D);
if (auto *E = N.get<Expr>())
return refInExpr(E);
- if (auto *NNSL = N.get<NestedNameSpecifierLoc>())
- return {ReferenceLoc{NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false,
- explicitReferenceTargets(DynTypedNode::create(
- *NNSL->getNestedNameSpecifier()))}};
+ if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
+ // (!) 'DeclRelation::Alias' ensures we do not loose namespace aliases.
+ return {ReferenceLoc{
+ NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false,
+ explicitReferenceTargets(
+ DynTypedNode::create(*NNSL->getNestedNameSpecifier()),
+ DeclRelation::Alias)}};
+ }
if (const TypeLoc *TL = N.get<TypeLoc>())
return refInTypeLoc(*TL);
if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69624.227130.patch
Type: text/x-patch
Size: 2449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191030/356c76b6/attachment-0001.bin>
More information about the cfe-commits
mailing list