[cfe-commits] r101198 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp test/CXX/temp/temp.decls/temp.friend/p1.cpp

John McCall rjmccall at apple.com
Tue Apr 13 17:24:33 PDT 2010


Author: rjmccall
Date: Tue Apr 13 19:24:33 2010
New Revision: 101198

URL: http://llvm.org/viewvc/llvm-project?rev=101198&view=rev
Log:
Parse friend template ids as types instead of ending up in
ActOnClassTemplateSpecialization and being very confused.
Fixes PR6514 (for non-templated-scope friends).


Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=101198&r1=101197&r2=101198&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Apr 13 19:24:33 2010
@@ -780,9 +780,6 @@
   Action::DeclResult TagOrTempResult = true; // invalid
   Action::TypeResult TypeResult = true; // invalid
 
-  // FIXME: When TUK == TUK_Reference and we have a template-id, we need
-  // to turn that template-id into a type.
-
   bool Owned = false;
   if (TemplateId) {
     // Explicit specialization, class template partial specialization,
@@ -806,7 +803,14 @@
                                              TemplateArgsPtr,
                                              TemplateId->RAngleLoc,
                                              AttrList);
-    } else if (TUK == Action::TUK_Reference) {
+
+    // Friend template-ids are treated as references unless
+    // they have template headers, in which case they're ill-formed
+    // (FIXME: "template <class T> friend class A<T>::B<int>;").
+    // We diagnose this error in ActOnClassTemplateSpecialization.
+    } else if (TUK == Action::TUK_Reference ||
+               (TUK == Action::TUK_Friend &&
+                TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
       TypeResult
         = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
                                       TemplateId->TemplateNameLoc,

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp?rev=101198&r1=101197&r2=101198&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp Tue Apr 13 19:24:33 2010
@@ -276,3 +276,20 @@
     return Foo<long>(t, true);
   }
 }
+
+// PR6514
+namespace test13 {
+  template <int N, template <int> class Temp>
+  class Role : public Temp<N> {
+    friend class Temp<N>;
+    int x;
+  };
+
+  template <int N> class Foo {
+    void foo(Role<N, test13::Foo> &role) {
+      (void) role.x;
+    }
+  };
+
+  template class Foo<0>;
+}





More information about the cfe-commits mailing list