cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Jan 2001 09:13:16 +0000 (09:13 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Jan 2001 09:13:16 +0000 (09:13 +0000)
* friend.c (make_friend_class): Make sure a templated class is
actually a template.
testsuite:
* g++.old-deja/g++.pt/friend47.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38939 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/friend.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.pt/friend47.C [new file with mode: 0644]

index 995f49e..1297b2f 100644 (file)
@@ -1,3 +1,8 @@
+2001-01-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * friend.c (make_friend_class): Make sure a templated class is
+       actually a template.
+
 2001-01-11  Nathan Sidwell  <nathan@codesourcery.com>
 
        * decl2.c (get_guard): Set linkage from guarded decl.
index df3281e..b817c7c 100644 (file)
@@ -225,32 +225,30 @@ make_friend_class (type, friend_type)
   else
     is_template_friend = 0;
 
-  if (is_template_friend 
-      && (TREE_CODE (friend_type) == TYPENAME_TYPE
-         || TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM))
+  /* [temp.friend]
+
+     A friend of a class or class template can be a function or
+     class template, a specialization of a function template or
+     class template, or an ordinary (nontemplate) function or
+     class. */
+  if (!is_template_friend)
+    ;/* ok */
+  else if (TREE_CODE (friend_type) == TYPENAME_TYPE)
     {
-      /* [temp.friend]
-
-          A friend of a class or class template can be a function or
-          class template, a specialization of a function template or
-          class template, or an ordinary (nontemplate) function or
-          class. 
-          
-        But, we're looking at something like:
-
-          template <class T> friend typename S<T>::X;
-
-        or:
-
-          template <class T> friend class T;
-
-        which isn't any of these.  */
-      if (TREE_CODE (friend_type) == TYPENAME_TYPE)
-       cp_error ("typename type `%T' declared `friend'",
-                 friend_type);
-      else
-       cp_error ("template parameter type `%T' declared `friend'",
-                 friend_type);
+      /* template <class T> friend typename S<T>::X; */
+      cp_error ("typename type `%#T' declared `friend'", friend_type);
+      return;
+    }
+  else if (TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM)
+    {
+      /* template <class T> friend class T; */
+      cp_error ("template parameter type `%T' declared `friend'", friend_type);
+      return;
+    }
+  else if (!CLASSTYPE_TEMPLATE_INFO (friend_type))
+    {
+      /* template <class T> friend class A; where A is not a template */
+      cp_error ("`%#T' is not a template", friend_type);
       return;
     }
 
index 7a37361..8c413ab 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.pt/friend47.C: New test.
+
 2001-01-11  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.old-deja/g++.pt/instantiate13.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/friend47.C b/gcc/testsuite/g++.old-deja/g++.pt/friend47.C
new file mode 100644 (file)
index 0000000..37aa921
--- /dev/null
@@ -0,0 +1,14 @@
+// Build don't link:
+
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 7 Jan 2001 <nathan@codesourcery.com>
+
+// Bug 1033. We ICE'd when trying to make a non template class a templated
+// friend.
+
+class A {};
+class B {
+  template<class T> friend class A;   // ERROR - not a template
+};
+
+