C++ PATCH: PR 16716, 17327

Mark Mitchell mark@codesourcery.com
Tue Sep 14 02:46:00 GMT 2004


This patch fixes PR 16716, a minor error-recovery regression in the
C++ front end, and PR 17327, a case where we failed to handle
unification of enumeration types correctly in templates.

Tested on i686-pc-linux-gnu, applied to the mainline, and (shortly) to
the 3.4 branch, with minor changes.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-09-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16716
	* parser.c (cp_parser_parse_and_diagnose_invalid_type_name):
	Robustify.

	PR c++/17327
	* pt.c (unify): Add ENUMERAL_TYPE case.  Replace sorry with
	gcc_unreacable.

2004-09-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16716
	* g++.dg/parse/crash17.C: New test.

	PR c++/17327
	* g++.dg/template/enum3.C: New test.

Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.245
diff -c -5 -p -r1.245 parser.c
*** cp/parser.c	10 Sep 2004 11:12:14 -0000	1.245
--- cp/parser.c	13 Sep 2004 23:38:22 -0000
*************** cp_parser_parse_and_diagnose_invalid_typ
*** 2284,2300 ****
  	  && dependent_type_p (parser->scope)))
      {
        cp_parser_abort_tentative_parse (parser);
        return false;
      }
!   if (!cp_parser_parse_definitely (parser))
      return false;
  
-   /* If we got here, this cannot be a valid variable declaration, thus
-      the cp_parser_id_expression must have resolved to a plain identifier
-      node (not a TYPE_DECL or TEMPLATE_ID_EXPR).  */
-   gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
    /* Emit a diagnostic for the invalid type.  */
    cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
    /* Skip to the end of the declaration; there's no point in
       trying to process it.  */
    cp_parser_skip_to_end_of_block_or_statement (parser);
--- 2284,2297 ----
  	  && dependent_type_p (parser->scope)))
      {
        cp_parser_abort_tentative_parse (parser);
        return false;
      }
!   if (!cp_parser_parse_definitely (parser)
!       || TREE_CODE (id) != IDENTIFIER_NODE)
      return false;
  
    /* Emit a diagnostic for the invalid type.  */
    cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
    /* Skip to the end of the declaration; there's no point in
       trying to process it.  */
    cp_parser_skip_to_end_of_block_or_statement (parser);
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.921
diff -c -5 -p -r1.921 pt.c
*** cp/pt.c	12 Sep 2004 04:45:46 -0000	1.921
--- cp/pt.c	13 Sep 2004 23:38:23 -0000
*************** unify (tree tparms, tree targs, tree par
*** 9973,9982 ****
--- 9973,9983 ----
      case REAL_TYPE:
      case COMPLEX_TYPE:
      case VECTOR_TYPE:
      case INTEGER_TYPE:
      case BOOLEAN_TYPE:
+     case ENUMERAL_TYPE:
      case VOID_TYPE:
        if (TREE_CODE (arg) != TREE_CODE (parm))
  	return 1;
        
        /* We have already checked cv-qualification at the top of the
*************** unify (tree tparms, tree targs, tree par
*** 10134,10147 ****
  	      && !template_args_equal (parm, arg))
  	    return 1;
  	  else
  	    return 0;
  	}
!       else
! 	sorry ("use of `%s' in template type unification",
! 	       tree_code_name [(int) TREE_CODE (parm)]);
! 
        return 1;
      }
  }
  
  /* Note that DECL can be defined in this translation unit, if
--- 10135,10145 ----
  	      && !template_args_equal (parm, arg))
  	    return 1;
  	  else
  	    return 0;
  	}
!       gcc_unreachable ();
        return 1;
      }
  }
  
  /* Note that DECL can be defined in this translation unit, if
Index: testsuite/g++.dg/template/enum3.C
===================================================================
RCS file: testsuite/g++.dg/template/enum3.C
diff -N testsuite/g++.dg/template/enum3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/enum3.C	13 Sep 2004 23:38:24 -0000
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/17327
+ 
+ enum E { E0, E1 };
+ template <class T,class U> class A {};
+ template <class T> void f(A<E,T>) {}
+ // We used to issue a "sorry" message.  By using an explicit error
+ // message below, we make sure that we will not match "sorry".
+ template void f(A<int,E>); // { dg-error "template-id" }
Index: testsuite/g++.dg/parse/crash17.C
===================================================================
RCS file: testsuite/g++.dg/parse/crash17.C
diff -N testsuite/g++.dg/parse/crash17.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/crash17.C	14 Sep 2004 00:27:48 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/16716
+ 
+ template <typename> class allocator; 
+  
+ template<typename T> class vector { 
+   // With the dg-error on the next line, we are really just trying to
+   // check that the message is not an ICE message.
+   typedef typename allocator<T> allocator_type; // { dg-error "expected|forbids" }
+ }; 



More information about the Gcc-patches mailing list