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++/31745: ICE on invalid use of namespace


Hi all.

The following invalid snippet triggers an ICE with the mainline:

=== cut here ===
void foo()
{
   namespace N {
=== cut here ===

The 'namespace N {' is not allowed here ('namespace N = foo;' would be),
and the code handles it by skipping all the tokens up to the closing
brace, and then consuming the next token.

In that particular case, there is no closing brace, so we end at the
EOF, and an assertion fails when consuming the next token.

The attached patch fixes this by ensuring that we've not reached the EOF
before trying to consume the next token.

I've regtested this on i386-apple-darwin8.9.1 with no new unexpected
failures. Is it OK for mainline?

Best regards,
Simon

:ADDPATCH c++:

2007-05-16  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/31745
	* parser.c (cp_parser_namespace_alias_definition): Don't try to
	consume the next token if the end of file has been reached.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 124776)
+++ gcc/cp/parser.c	(working copy)
@@ -11296,7 +11296,8 @@ cp_parser_namespace_alias_definition (cp
       /* Skip the definition.  */
       cp_lexer_consume_token (parser->lexer);
       cp_parser_skip_to_closing_brace (parser);
-      cp_lexer_consume_token (parser->lexer);
+      if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
+	cp_lexer_consume_token (parser->lexer);
       return;
     }
   cp_parser_require (parser, CPP_EQ, "`='");

2007-05-16  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/31745
	* g++.dg/parse/crash34.C: New test.

/* PR c++/31745 */
/* { dg-do "compile" }  */

void foo()
{
  namespace N { /* { dg-error "is not allowed|at end of input" } */


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