[RFC] PR c/23722 bad error recovery with if blocks and else

Manuel López-Ibáñez lopezibanez@gmail.com
Thu Nov 22 20:01:00 GMT 2007


On 22/11/2007, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Thu, 22 Nov 2007, Manuel López-Ibáñez wrote:
>
> > 2007-11-22  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> >
> >   PR c/23722
> >  * c-parser.c (struct c_parser): New bit in_if_stmt.
> >   (c_parser_compound_statement_nostart): Handle unexpected 'else' keyword.
>
> This doesn't mention the c_parser_if_body changes.  By changing that
> function, it looks like in_if_stmt will be set inside the "else" part of
> an if statement; is the error that '}' is expected before 'else' still
> appropriate there?
>
> if (...) { ... } else { stray else; }
>

I didn't realise that c_parser_if_body is also used to parse the body
of 'else'.

Also, looking into that I realised that there is another problem:

if (...) {.... {...else;} } would report "expected '}' before 'else'
two times (one for each opening brace).

I need to set in_if_stmt to false when we enter a new block that is
not a the body of 'if' but that doesn't seem so straightforward...

Cheers,

Manuel.



More information about the Gcc-patches mailing list