re PR c++/28637 (ICE on invalid template parameter)
authorLee Millward <lee.millward@codesourcery.com>
Wed, 9 Aug 2006 18:43:06 +0000 (18:43 +0000)
committerLee Millward <lmillward@gcc.gnu.org>
Wed, 9 Aug 2006 18:43:06 +0000 (18:43 +0000)
2006-08-09  Lee Millward  <lee.millward@codesourcery.com>

       PR c++/28637
       * pt.c (coerce_template_parms): Copy across the
       invalid template arguments to the new template inner arguments.
       (retrieve_specialization): Robustify.

       * g++.dg/template/void3.C: New test.

       PR c++/28638
       * pt.c (coerce_template_template_parms): Robustify.

       * g++.dg/template/void4.C: New test.

       PR c++/28639
       * error.c (dump_template_parms): Robustify.

       PR c++/28640
       * pt.c (redeclare_class_template): Robustify

       * g++.dg/template/void5.C: New test.

       PR c++/28641
       * pt.c (type_unification_real): Robustify.

From-SVN: r116043

gcc/cp/ChangeLog
gcc/cp/error.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/void3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/void4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/void5.C [new file with mode: 0644]

index 1f05b730aa82e549f3d1145d0c2b1aa1ce899791..1106f86b0c77c2dbbaedff6c53f41217008f569f 100644 (file)
@@ -1,3 +1,22 @@
+2006-08-09  Lee Millward  <lee.millward@codesourcery.com>
+
+       PR c++/28637
+       * pt.c (coerce_template_parms): Copy across the
+       invalid template arguments to the new template inner arguments.
+       (retrieve_specialization): Robustify.
+
+       PR c++/28638
+       * pt.c (coerce_template_template_parms): Robustify.
+
+       PR c++/28639
+       * error.c (dump_template_parms): Robustify.
+
+       PR c++/28640
+       * pt.c (redeclare_class_template): Robustify.
+
+       PR c++/28641
+       * pt.c (type_unification_real): Robustify.
+       
 2006-08-03  Lee Millward  <lee.millward@codesourcery.com>
 
        PR c++/28347
index d6c813da7a7f7409e018f6d0a73718c3a53e91aa..f87355893cbc2922e999be1c9be24cb3dc75609d 100644 (file)
@@ -1242,7 +1242,15 @@ dump_template_parms (tree info, int primary, int flags)
 
       for (ix = 0; ix != len; ix++)
        {
-         tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
+         tree parm;
+
+          if (TREE_VEC_ELT (parms, ix) == error_mark_node)
+            {
+              pp_identifier (cxx_pp, "<template parameter error>");
+              continue;
+            }
+
+          parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
 
          if (ix)
            pp_separate_with_comma (cxx_pp);
index c0205a419c7c2c4fa5bcd8d71ed01c54a4096de0..c744759899b9cac32e8a17c3e404aabfc3151fa1 100644 (file)
@@ -816,6 +816,9 @@ static tree
 retrieve_specialization (tree tmpl, tree args,
                         bool class_specializations_p)
 {
+  if (args == error_mark_node)
+    return NULL_TREE;
+
   gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
 
   /* There should be as many levels of arguments as there are
@@ -3320,10 +3323,19 @@ redeclare_class_template (tree type, tree parms)
 
   for (i = 0; i < TREE_VEC_LENGTH (tmpl_parms); ++i)
     {
-      tree tmpl_parm = TREE_VALUE (TREE_VEC_ELT (tmpl_parms, i));
-      tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
-      tree tmpl_default = TREE_PURPOSE (TREE_VEC_ELT (tmpl_parms, i));
-      tree parm_default = TREE_PURPOSE (TREE_VEC_ELT (parms, i));
+      tree tmpl_parm;
+      tree parm;
+      tree tmpl_default;
+      tree parm_default;
+
+      if (TREE_VEC_ELT (tmpl_parms, i) == error_mark_node
+          || TREE_VEC_ELT (parms, i) == error_mark_node)
+        continue;
+
+      tmpl_parm = TREE_VALUE (TREE_VEC_ELT (tmpl_parms, i));
+      parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
+      tmpl_default = TREE_PURPOSE (TREE_VEC_ELT (tmpl_parms, i));
+      parm_default = TREE_PURPOSE (TREE_VEC_ELT (parms, i));
 
       /* TMPL_PARM and PARM can be either TYPE_DECL, PARM_DECL, or
         TEMPLATE_DECL.  */
@@ -3785,7 +3797,8 @@ coerce_template_template_parms (tree parm_parms,
 
   for (i = 0; i < nparms; ++i)
     {
-      if (TREE_VEC_ELT (parm_parms, i) == error_mark_node)
+      if (TREE_VEC_ELT (parm_parms, i) == error_mark_node
+          || TREE_VEC_ELT (arg_parms, i) == error_mark_node)
         continue;
 
       parm = TREE_VALUE (TREE_VEC_ELT (parm_parms, i));
@@ -4073,7 +4086,10 @@ coerce_template_parms (tree parms,
       parm = TREE_VEC_ELT (parms, i);
  
       if (parm == error_mark_node)
+      {
+        TREE_VEC_ELT (new_inner_args, i) = error_mark_node;
         continue;
+      }
 
       /* Calculate the Ith argument.  */
       if (i < nargs)
@@ -9788,7 +9804,12 @@ type_unification_real (tree tparms,
     for (i = 0; i < ntparms; i++)
       if (!TREE_VEC_ELT (targs, i))
        {
-         tree tparm = TREE_VALUE (TREE_VEC_ELT (tparms, i));
+         tree tparm;
+
+          if (TREE_VEC_ELT (tparms, i) == error_mark_node)
+            continue;
+
+          tparm = TREE_VALUE (TREE_VEC_ELT (tparms, i));
 
          /* If this is an undeduced nontype parameter that depends on
             a type parameter, try another pass; its type may have been
index 6e415c3f341fec78a9de8fe57c98238a97e3c063..26af1f4959c910c1783648c55e042b1c141ea88b 100644 (file)
@@ -1,3 +1,14 @@
+2006-08-09  Lee Millward  <lee.millward@codesourcery.com>
+
+       PR c++/28637
+       * g++.dg/template/void3.C: New test.
+
+       PR c++/28638
+       * g++.dg/template/void4.C: New test.
+
+`       PR c++/28640
+       * g++.dg/template/void5.C: New test.
+       
 2006-08-07  Danny Smith  <dannysmith@users.sourceforge.net>
 
        * g++.dg/ext/visibility/class1.C (dg-require-visibility): Move
diff --git a/gcc/testsuite/g++.dg/template/void3.C b/gcc/testsuite/g++.dg/template/void3.C
new file mode 100644 (file)
index 0000000..6526a2a
--- /dev/null
@@ -0,0 +1,5 @@
+//PR c++/28637
+
+template<void> struct A {};  // { dg-error "not a valid type" }
+A<0> a;
+
diff --git a/gcc/testsuite/g++.dg/template/void4.C b/gcc/testsuite/g++.dg/template/void4.C
new file mode 100644 (file)
index 0000000..7d264fb
--- /dev/null
@@ -0,0 +1,7 @@
+//PR c++/28638
+
+template<void> struct A;  // { dg-error "not a valid type" }
+
+template<template<int> class> struct B {};
+
+B<A> b;
diff --git a/gcc/testsuite/g++.dg/template/void5.C b/gcc/testsuite/g++.dg/template/void5.C
new file mode 100644 (file)
index 0000000..bef9b91
--- /dev/null
@@ -0,0 +1,5 @@
+//PR c++/28640
+
+template<void> struct A; // { dg-error "not a valid type" }
+template<int> struct A;