r226083 - PR13699: Include friend declarations in code completion results if they had a

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 14 18:27:20 PST 2015


Author: rsmith
Date: Wed Jan 14 20:27:20 2015
New Revision: 226083

URL: http://llvm.org/viewvc/llvm-project?rev=226083&view=rev
Log:
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!

Added:
    cfe/trunk/test/Index/complete-template-friends-defined.cpp
Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=226083&r1=226082&r2=226083&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Jan 14 20:27:20 2015
@@ -495,7 +495,6 @@ bool ResultBuilder::isInterestingDecl(co
   AsNestedNameSpecifier = false;
 
   ND = ND->getUnderlyingDecl();
-  unsigned IDNS = ND->getIdentifierNamespace();
 
   // Skip unnamed entities.
   if (!ND->getDeclName())
@@ -503,7 +502,7 @@ bool ResultBuilder::isInterestingDecl(co
   
   // 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(A
                                        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)

Added: cfe/trunk/test/Index/complete-template-friends-defined.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-template-friends-defined.cpp?rev=226083&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-template-friends-defined.cpp (added)
+++ cfe/trunk/test/Index/complete-template-friends-defined.cpp Wed Jan 14 20:27:20 2015
@@ -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)





More information about the cfe-commits mailing list