This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c++/36411, ICE in coerce_template_template_parms


The attached testcase hits gcc_unreachable in the switch statement
in coerce_template_template_parms. TREE_VEC_ELT (parm_parms, nparms - 1)
is not an error_mark_node (therefore the check before the switch
statement passes), but its TREE_VALUE and therefore PARM is an
error_mark_node.
The patch fixes the problem by checking PARM for error_mark_node
instead. This check covers the previous check, because
TREE_VALUE(error_mark_node) == error_mark_node. (The rest of the
first hunk is just new indentation for the switch statement).

The 2nd and 3rd hunk of the patch remove some superfluous checks
for error_mark_node prior to coerce_template_template_parm which
checks for error_mark_node anyway.

Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline?

Regards,
Volker


2008-06-01  Volker Reichelt  <v.reichelt@netcologne.de>

	PR c++/36411
	* pt.c (coerce_template_template_parms): Check PARM for
	error_mark_node.  Remove redundant checks.

========================================================================
--- gcc/cp/pt.c	2008-05-30 19:22:14 +0200
+++ gcc/cp/pt.c	2008-06-01 10:09:40 +0200
@@ -4728,26 +4728,25 @@ coerce_template_template_parms (tree par
 
   /* Determine whether we have a parameter pack at the end of the
      template template parameter's template parameter list.  */
-  if (TREE_VEC_ELT (parm_parms, nparms - 1) != error_mark_node)
+  parm = TREE_VALUE (TREE_VEC_ELT (parm_parms, nparms - 1));
+  if (parm == error_mark_node)
+    return 0;
+
+  switch (TREE_CODE (parm))
     {
-      parm = TREE_VALUE (TREE_VEC_ELT (parm_parms, nparms - 1));
-      
-      switch (TREE_CODE (parm))
-        {
-        case TEMPLATE_DECL:
-        case TYPE_DECL:
-          if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm)))
-            variadic_p = 1;
-          break;
-	  
-        case PARM_DECL:
-          if (TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
-            variadic_p = 1;
-          break;
-	  
-        default:
-          gcc_unreachable ();
-        }
+    case TEMPLATE_DECL:
+    case TYPE_DECL:
+      if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm)))
+	variadic_p = 1;
+      break;
+
+    case PARM_DECL:
+      if (TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+	variadic_p = 1;
+      break;
+
+    default:
+      gcc_unreachable ();
     }
  
   if (nargs != nparms
@@ -4758,17 +4757,12 @@ coerce_template_template_parms (tree par
      the end (if any).  */
   for (i = 0; i < nparms - variadic_p; ++i)
     {
-      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));
       arg = TREE_VALUE (TREE_VEC_ELT (arg_parms, i));
 
       if (!coerce_template_template_parm (parm, arg, complain, in_decl,
                                           outer_args))
 	return 0;
-
     }
 
   if (variadic_p)
@@ -4776,16 +4770,10 @@ coerce_template_template_parms (tree par
       /* Check each of the template parameters in the template
 	 argument against the template parameter pack at the end of
 	 the template template parameter.  */
-      if (TREE_VEC_ELT (parm_parms, i) == error_mark_node)
-	return 0;
-
       parm = TREE_VALUE (TREE_VEC_ELT (parm_parms, i));
 
       for (; i < nargs; ++i)
         {
-          if (TREE_VEC_ELT (arg_parms, i) == error_mark_node)
-            continue;
- 
           arg = TREE_VALUE (TREE_VEC_ELT (arg_parms, i));
  
           if (!coerce_template_template_parm (parm, arg, complain, in_decl,
========================================================================

2008-06-01  Volker Reichelt  <v.reichelt@netcologne.de>

	PR c++/36411
	* g++.dg/template/ttp28.C: New testcase.

========================================================================
--- gcc/testsuite/g++.dg/template/ttp28.C	2003-09-23 19:59:22 +0200
+++ gcc/testsuite/g++.dg/template/ttp28.C	2008-06-01 18:22:04 +0200
@@ -0,0 +1,8 @@
+// PR c++/36411
+
+template<template<void> class>  // { dg-error "not a valid type" }
+struct A
+{
+  template<template<int> class T>
+  A<T> foo();  // { dg-error "mismatch|expected|invalid" }
+};
========================================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]