]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/8442 (rejects nested template classes)
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Wed, 18 Dec 2002 14:58:35 +0000 (14:58 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Wed, 18 Dec 2002 14:58:35 +0000 (14:58 +0000)
PR c++/8442
* decl2.c (handle_class_head): Verify if the looked up name is a
type or template.
* pt.c (convert_template_argument): Fix type or template template
parameter decision logic.

* g++.dg/template/type2.C: New test.
* g++.dg/template/ttp3.C: Change expected error message.

From-SVN: r60249

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/ttp3.C
gcc/testsuite/g++.dg/template/type2.C [new file with mode: 0644]

index b5557237a2859ba7da4b6386c82f541dc8a8d1f3..3e52602babc2b6934cef17c0b49ca34384cd2875 100644 (file)
@@ -1,3 +1,11 @@
+2002-12-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/8442
+       * decl2.c (handle_class_head): Verify if the looked up name is a
+       type or template.
+       * pt.c (convert_template_argument): Fix type or template template
+       parameter decision logic.
+
 2002-12-13  Joe Buck <jbuck@synopsys.com>
 
        * parse.y (class_head_defn): Set CLASSTYPE_DECLARED_CLASS for
index 1e8101a6bd1576236f288a8f9533d0e62702d9f2..1dbaaf4b27e79e56e4f5e8a251d02cf90808b93e 100644 (file)
@@ -5241,6 +5241,7 @@ handle_class_head (aggr, scope, id, defn_p, new_type_p)
      int *new_type_p;
 {
   tree decl = NULL_TREE;
+  tree type;
   tree current = current_scope ();
   bool xrefd_p = false;
   
@@ -5289,12 +5290,28 @@ handle_class_head (aggr, scope, id, defn_p, new_type_p)
       xrefd_p = true;
     }
 
-  if (!TYPE_BINFO (TREE_TYPE (decl)))
+  type = TREE_TYPE (decl);
+
+  if (!TYPE_BINFO (type))
     {
       error ("`%T' is not a class or union type", decl);
       return error_mark_node;
     }
-  
+
+  /* When `A' is a template class, using `class A' without template
+     argument is invalid unless
+     - we are inside the scope of the template class `A' or one of its
+       specialization.
+     - we are declaring the template class `A' itself.  */
+  if (TREE_CODE (type) == RECORD_TYPE
+      && CLASSTYPE_IS_TEMPLATE (type)
+      && processing_template_decl <= template_class_depth (current)
+      && ! is_base_of_enclosing_class (type, current_class_type))
+    {
+      error ("template argument is required for `%T'", type);
+      return error_mark_node;
+    }
+
   if (defn_p)
     {
       /* For a definition, we want to enter the containing scope
index c6fbff44f9aa75aa2bc7d5d37024d16b4ecf94b3..22304bd0a91b9d4719911c3ed58c74338b30ae75 100644 (file)
@@ -3303,17 +3303,12 @@ convert_template_argument (parm, arg, args, complain, i, in_decl)
                     && TREE_CODE (DECL_TEMPLATE_RESULT (arg)) == TYPE_DECL)
                    || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM
                    || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE);
-  else if (CLASSTYPE_TEMPLATE_INFO (arg) && !CLASSTYPE_USE_TEMPLATE (arg)
-          && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (arg)))
-    {
-      if (is_base_of_enclosing_class (arg, current_class_type))
-       /* This is a template name used within the scope of the
-          template. It could be the template, or it could be the
-          instantiation. Choose whichever makes sense.  */
-       is_tmpl_type = requires_tmpl_type;
-      else
-       is_tmpl_type = 1;
-    }
+  else if (CLASSTYPE_IS_TEMPLATE (arg)
+          && is_base_of_enclosing_class (arg, current_class_type))
+    /* This is a template name used within the scope of the
+       template. It could be the template, or it could be the
+       instantiation. Choose whichever makes sense.  */
+    is_tmpl_type = requires_tmpl_type;
   else
     /* It is a non-template class, or a specialization of a template
        class, or a non-template member of a template class.  */
index bb479eca3dc095e3275c6efd06bf4497c0e9c5e8..735eb975d90061e91ad33088ccac337ffdc7cbd6 100644 (file)
@@ -1,3 +1,9 @@
+2002-12-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/8442
+       * g++.dg/template/type2.C: New test.
+       * g++.dg/template/ttp3.C: Change expected error message.
+
 2002-12-17  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/execute/20021118-3.c: New test.
index 05bd44a172eaf8f4e942787c587d707b36b62e77..fe9bd9eb3821cc0cbcc32977a95f347b0c8d8fd1 100644 (file)
@@ -14,7 +14,7 @@ class OUTER {
   template <class T>
   class List { };
   
-  vector<class List> data; // { dg-error "type/value mismatch|expected a type|ISO C" "" }
+  vector<class List> data; // { dg-error "argument is required|ISO C" "" }
 };
 
 template <class T>
diff --git a/gcc/testsuite/g++.dg/template/type2.C b/gcc/testsuite/g++.dg/template/type2.C
new file mode 100644 (file)
index 0000000..509c482
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// Origin: Juan Carlos Arevalo-Baeza <jcab@JCABs-Rumblings.com>
+
+// PR c++/8442
+// Type template parameter incorrectly treated as template template
+// parameter.
+
+template <typename T> struct A {};
+
+template <typename T> struct B
+{
+  template <typename U> struct C {};
+  template <typename U> A<C<U> > foo(U);
+};
+
+B<void> b;