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]

Re: don't issue duplicate template errors


On Feb  1, 2005, Alexandre Oliva <aoliva@redhat.com> wrote:

> Testing in 3.4 now, I'll check it in the branch as soon as testing
> completes.

Here's the patch, back-ported to 3.4, where the comparison with
start_of_id was spelled a bit differently.  I'm checking it in.

Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* g++.dg/parse/typename7.C: Adjust error messages.

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/18757
	PR c++/19366
	PR c++/19499
	* parser.c (cp_parser_template_id): Revert 2004-12-09's patch.
	Issue an error when creating the template id.
	* pt.c (fn_type_unification): Return early if the explicit
	template arg list is an error_mark_node.

Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.157.2.50
diff -u -p -r1.157.2.50 parser.c
--- gcc/cp/parser.c 27 Jan 2005 12:54:35 -0000 1.157.2.50
+++ gcc/cp/parser.c 1 Feb 2005 06:09:50 -0000
@@ -8015,7 +8015,7 @@ cp_parser_template_id (cp_parser *parser
      the effort required to do the parse, nor will we issue duplicate
      error messages about problems during instantiation of the
      template.  */
-  if (start_of_id >= 0 && !cp_parser_error_occurred (parser))
+  if (start_of_id >= 0)
     {
       cp_token *token;
 
@@ -8031,6 +8031,13 @@ cp_parser_template_id (cp_parser *parser
       token->keyword = RID_MAX;
       /* Purge all subsequent tokens.  */
       cp_lexer_purge_tokens_after (parser->lexer, token);
+
+      /* ??? Can we actually assume that, if template_id ==
+	 error_mark_node, we will have issued a diagnostic to the
+	 user, as opposed to simply marking the tentative parse as
+	 failed?  */
+      if (cp_parser_error_occurred (parser) && template_id != error_mark_node)
+	error ("parse error in template argument list");
     }
 
   pop_deferring_access_checks ();
Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.816.2.49
diff -u -p -r1.816.2.49 pt.c
--- gcc/cp/pt.c 19 Jan 2005 14:46:24 -0000 1.816.2.49
+++ gcc/cp/pt.c 1 Feb 2005 06:09:57 -0000
@@ -8935,6 +8935,9 @@ fn_type_unification (tree fn, 
       tree converted_args;
       bool incomplete;
 
+      if (explicit_targs == error_mark_node)
+	return 1;
+
       converted_args
 	= (coerce_template_parms (DECL_INNERMOST_TEMPLATE_PARMS (fn), 
 				  explicit_targs, NULL_TREE, tf_none, 
Index: gcc/testsuite/g++.dg/parse/typename7.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/parse/typename7.C,v
retrieving revision 1.1.10.1
diff -u -p -r1.1.10.1 typename7.C
--- gcc/testsuite/g++.dg/parse/typename7.C 23 Dec 2004 16:25:50 -0000 1.1.10.1
+++ gcc/testsuite/g++.dg/parse/typename7.C 1 Feb 2005 06:09:57 -0000
@@ -9,23 +9,23 @@ struct A
 {
   template<typename>   void foo(int);
   template<typename T> void bar(T t) {
-    this->foo<typename T>(t); } // { dg-error "expected" }
+    this->foo<typename T>(t); } // { dg-error "expected|parse error|no matching" }
   template<typename T> void bad(T t) {
-    foo<typename T>(t); } // { dg-error "expected" }
+    foo<typename T>(t); } // { dg-error "expected|parse error" }
 };
 
 template <typename T>
 struct B
 {
   void bar(T t) {
-    A().bar<typename T>(t); } // { dg-error "expected" }
+    A().bar<typename T>(t); } // { dg-error "expected|parse error|no matching" }
   void bad(T t) {
     B<typename T>::bar(t); } // { dg-error "invalid|not a template" }
 };
 
 void baz()
 {
-    A().bar(0);
-    A().bad(0);
-    B<int>().bar(0);
+  A().bar(0);
+  A().bad(0);
+  B<int>().bar(0);
 }
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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