summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-01-15 02:27:20 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-01-15 02:27:20 +0000
commit6eece29d8ff88a9c90620a9b026fc8304de6f6ea (patch)
tree29cedbe5996b3f5c8e2234249e82c4d63981c811 /clang
parenta61ef990dd4dee169d2d6d050ebdf56bf2893a22 (diff)
downloadbcm5719-llvm-6eece29d8ff88a9c90620a9b026fc8304de6f6ea.tar.gz
bcm5719-llvm-6eece29d8ff88a9c90620a9b026fc8304de6f6ea.zip
PR13699: Include friend declarations in code completion results if they had a
prior visible declaration. Prefer to take template parameter names from the first declaration. Testcase from a patch by Francisco Lopes! llvm-svn: 226083
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp9
-rw-r--r--clang/test/Index/complete-template-friends-defined.cpp33
2 files changed, 39 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 48bdd2a7d82..384972bc728 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -495,7 +495,6 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND,
AsNestedNameSpecifier = false;
ND = ND->getUnderlyingDecl();
- unsigned IDNS = ND->getIdentifierNamespace();
// Skip unnamed entities.
if (!ND->getDeclName())
@@ -503,7 +502,7 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND,
// Friend declarations and declarations introduced due to friends are never
// added as results.
- if (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend))
+ if (ND->getFriendObjectKind() == Decl::FOK_Undeclared)
return false;
// Class template (partial) specializations are never added as results.
@@ -2309,7 +2308,11 @@ static void AddTemplateParameterChunks(ASTContext &Context,
unsigned Start = 0,
bool InDefaultArg = false) {
bool FirstParameter = true;
-
+
+ // Prefer to take the template parameter names from the first declaration of
+ // the template.
+ Template = cast<TemplateDecl>(Template->getCanonicalDecl());
+
TemplateParameterList *Params = Template->getTemplateParameters();
TemplateParameterList::iterator PEnd = Params->end();
if (MaxParameters)
diff --git a/clang/test/Index/complete-template-friends-defined.cpp b/clang/test/Index/complete-template-friends-defined.cpp
new file mode 100644
index 00000000000..f1d09c1f33d
--- /dev/null
+++ b/clang/test/Index/complete-template-friends-defined.cpp
@@ -0,0 +1,33 @@
+// The run lines are below, because this test is line- and
+// column-number sensitive.
+
+namespace N {
+ template<typename T> struct A {
+ template<typename U> friend class B;
+ };
+
+ template<typename T> struct B { };
+}
+
+void foo() {
+ N::A<int> a1;
+ N::A<int> a2;
+}
+
+namespace M {
+ template<typename T> struct C {
+ template<typename U> friend struct C;
+ };
+}
+
+void bar() {
+ M::C<int> c1;
+ M::C<int> c2;
+}
+
+// RUN: c-index-test -code-completion-at=%s:14:6 %s | FileCheck -check-prefix=CHECK-ACCESS-1 %s
+// CHECK-ACCESS-1: ClassTemplate:{TypedText A}{LeftAngle <}{Placeholder typename T}{RightAngle >} (50)
+// CHECK-ACCESS-1: ClassTemplate:{TypedText B}{LeftAngle <}{Placeholder typename T}{RightAngle >} (50)
+
+// RUN: c-index-test -code-completion-at=%s:25:6 %s | FileCheck -check-prefix=CHECK-ACCESS-2 %s
+// CHECK-ACCESS-2: ClassTemplate:{TypedText C}{LeftAngle <}{Placeholder typename T}{RightAngle >} (50)
OpenPOWER on IntegriCloud