On Wed, Oct 05, 2016 at 03:14:25PM +0200, Marek Polacek wrote:
> This is my attempt to implement P0305R1, Selection statements with 
> initializer.
> It allows the users to write
> 
>   if (init; cond) // ...
> 
> which is equivalent to
> 
>   {
>     init
>     if (cond) // ...
>   }

Well, it isn't exactly equivalent, because unlike { init; if (cond) /* ... */; }
there aren't two scopes, but just one.  So I'd say you should have tests
that verify that init and cond are indeed in the same scope, e.g. by trying
something like if (int c = 5; int c = 5) ... and verifying dg-error is
reported.

> +     case CPP_CLOSE_PAREN:
> +       /* If the next token is a non-nested '(', then we have reached
> +          the end of the if condition.  */

Looks like typo, shouldn't that be ')' ?

Also, do you really need two counters?

> +       if (paren_depth-- == 0)
> +         return false;
> +       break;
> +
> +     case CPP_OPEN_PAREN:
> +       ++paren_depth;
> +       break;
> +
> +     case CPP_CLOSE_BRACE:
> +       --brace_depth;

I mean, shouldn't you also stop before } when seeing if (int a = }; b)
rather than wrapping around?

> +      /* Consume the token.  */
> +      cp_lexer_consume_token (parser->lexer);
> +    }

Also, do you really need to consume all the tokens and then rollback, rather
than just use peek_nth_token with the index increasing in each iteration?

        Jakub

Reply via email to