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: [PATCH] Fix PR c++/29731: ICE with statement expression as template parameter


Simon Martin wrote:

> 2006-12-07  Simon Martin  <simartin@users.sourceforge.net>
> 
> 	PR c++/29731
> 	* parser.c (cp_parser_primary_expression): Return error_mark_node when
> 	a statement-expression is found outside of a function body.

Good analysis.

I think that you could make this a bit tidier though: just declare
error_p inside this scope:

       /* If we see `( { ' then we are looking at the beginning of

           a GNU statement-expression.  */
        if (cp_parser_allow_gnu_extensions_p (parser)
            && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
          {

Then, after:

            /* Finish up.  */
            expr = finish_stmt_expr (expr, false);

add:

  if (error_p)
    expr = error_mark_node;

But, I'm not willing to trust that the entire rest of the front end can
deal with statement expressions outside of function bodies.  So, let's
just give the user an error, and move on.  So, change that code to do:

            if (!parser->in_function_body)
              {
                error ("statement-expressions are allowed only inside
functions");
                skip_to_end_of_block_or_statement (parser);
                expr = error_mark_node;
             } else {
                /* parse it */
             }

That patch is pre-approved, after testing.

Thanks,

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


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