PATCH: PR c++/30863

Mark Mitchell mark@codesourcery.com
Fri Mar 23 05:26:00 GMT 2007


This patch fixes PR c++/30863, an accepts-invalid regression.  We have
a routine that's supposed to issue errors about things that look like
types, but aren't.  It's supposed to either (a) consume some tokens
and issue an error, or (b) not.  But, instead, it was consuming tokens
-- but not issuing an error.  That caused us to silently skip over the
errneous code.

Tested oon x86_64-unknown-linux-gnu, applied on the mainline and on
the 4.2 branch.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2007-03-22  Mark Mitchell  <mark@codesourcery.com>

	PR c++/30863
	* parser.c (cp_parser_parse_and_diagnose_invalid_type_name): Do
	not consume tokens when failing.

2007-03-22  Mark Mitchell  <mark@codesourcery.com>

	PR c++/30863
	* g++.dg/template/error24.C: New test.
	* g++.dg/parse/tmpl-outside1.C: Tweak error markers.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 123010)
+++ gcc/cp/parser.c	(working copy)
@@ -2281,12 +2281,13 @@ cp_parser_parse_and_diagnose_invalid_typ
      the scope is dependent, we cannot do much.  */
   if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)
       || (parser->scope && TYPE_P (parser->scope)
-	  && dependent_type_p (parser->scope)))
+	  && dependent_type_p (parser->scope))
+      || TREE_CODE (id) == TYPE_DECL)
     {
       cp_parser_abort_tentative_parse (parser);
       return false;
     }
-  if (!cp_parser_parse_definitely (parser) || TREE_CODE (id) == TYPE_DECL)
+  if (!cp_parser_parse_definitely (parser))
     return false;
 
   /* Emit a diagnostic for the invalid type.  */
Index: gcc/testsuite/g++.dg/parse/tmpl-outside1.C
===================================================================
--- gcc/testsuite/g++.dg/parse/tmpl-outside1.C	(revision 123010)
+++ gcc/testsuite/g++.dg/parse/tmpl-outside1.C	(working copy)
@@ -7,5 +7,4 @@ struct X
    template <int i> struct Y {};
 };
 
-typedef X::template Y<0> y; // { dg-error "template" }
-// { dg-bogus "with no type" "" { xfail *-*-* } 10 }
+typedef X::template Y<0> y; // { dg-error "template|invalid" }
Index: gcc/testsuite/g++.dg/template/error24.C
===================================================================
--- gcc/testsuite/g++.dg/template/error24.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/error24.C	(revision 0)
@@ -0,0 +1,8 @@
+// PR c++/30863
+
+template <typename T>
+struct s {};
+
+void f() {
+  unsigned s<int> x; // { dg-error "invalid" }
+}



More information about the Gcc-patches mailing list