[clang-tools-extra] r373104 - [clangd] Fix template type aliases in findExplicitReference
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 10:55:47 PDT 2019
Author: ibiryukov
Date: Fri Sep 27 10:55:46 2019
New Revision: 373104
URL: http://llvm.org/viewvc/llvm-project?rev=373104&view=rev
Log:
[clangd] Fix template type aliases in findExplicitReference
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68124
Modified:
clang-tools-extra/trunk/clangd/FindTarget.cpp
clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
Modified: clang-tools-extra/trunk/clangd/FindTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindTarget.cpp?rev=373104&r1=373103&r2=373104&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/FindTarget.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindTarget.cpp Fri Sep 27 10:55:46 2019
@@ -477,13 +477,6 @@ Optional<ReferenceLoc> refInTypeLoc(Type
Ref->Qualifier = L.getQualifierLoc();
}
- void VisitDeducedTemplateSpecializationTypeLoc(
- DeducedTemplateSpecializationTypeLoc L) {
- Ref = ReferenceLoc{
- NestedNameSpecifierLoc(), L.getNameLoc(),
- explicitReferenceTargets(DynTypedNode::create(L.getType()))};
- }
-
void VisitTagTypeLoc(TagTypeLoc L) {
Ref =
ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), {L.getDecl()}};
@@ -495,9 +488,25 @@ Optional<ReferenceLoc> refInTypeLoc(Type
}
void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) {
+ // We must ensure template type aliases are included in results if they
+ // were written in the source code, e.g. in
+ // template <class T> using valias = vector<T>;
+ // ^valias<int> x;
+ // 'explicitReferenceTargets' will return:
+ // 1. valias with mask 'Alias'.
+ // 2. 'vector<int>' with mask 'Underlying'.
+ // we want to return only #1 in this case.
Ref = ReferenceLoc{
NestedNameSpecifierLoc(), L.getTemplateNameLoc(),
- explicitReferenceTargets(DynTypedNode::create(L.getType()))};
+ explicitReferenceTargets(DynTypedNode::create(L.getType()),
+ DeclRelation::Alias)};
+ }
+ void VisitDeducedTemplateSpecializationTypeLoc(
+ DeducedTemplateSpecializationTypeLoc L) {
+ Ref = ReferenceLoc{
+ NestedNameSpecifierLoc(), L.getNameLoc(),
+ explicitReferenceTargets(DynTypedNode::create(L.getType()),
+ DeclRelation::Alias)};
}
void VisitDependentTemplateSpecializationTypeLoc(
Modified: clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp?rev=373104&r1=373103&r2=373104&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp Fri Sep 27 10:55:46 2019
@@ -615,20 +615,18 @@ TEST_F(FindExplicitReferencesTest, All)
)cpp",
"0: targets = {vector<int>}\n"
"1: targets = {vector<bool>}\n"},
- // FIXME: Fix 'allTargetDecls' to return alias template and re-enable.
// Template type aliases.
- // {R"cpp(
- // template <class T> struct vector { using value_type = T; };
- // template <> struct vector<bool> { using value_type = bool; };
- // template <class T> using valias = vector<T>;
- // void foo() {
- // $0^valias<int> vi;
- // $1^valias<bool> vb;
- // }
- // )cpp",
- // "0: targets = {valias}\n"
- // "1: targets = {valias}\n"},
-
+ {R"cpp(
+ template <class T> struct vector { using value_type = T; };
+ template <> struct vector<bool> { using value_type = bool; };
+ template <class T> using valias = vector<T>;
+ void foo() {
+ $0^valias<int> vi;
+ $1^valias<bool> vb;
+ }
+ )cpp",
+ "0: targets = {valias}\n"
+ "1: targets = {valias}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
struct X { void func(int); }
More information about the cfe-commits
mailing list