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: C++ PATCH for C++17 selection statements with initializer


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


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