On Tue, May 22, 2018 at 7:25 PM, Marek Polacek <pola...@redhat.com> wrote:
> On Mon, May 21, 2018 at 09:51:44PM -0400, Jason Merrill wrote:
>> On Mon, May 21, 2018 at 7:34 PM, Marek Polacek <pola...@redhat.com> wrote:
>> > The previous version of this patch got confused by
>> >
>> >   for (int i = 0; n > 0 ? true : false; i++)
>> >     // ...
>> >
>> > because even though we see a ; followed by a :, it's not a range-based for 
>> > with
>> > an initializer.  I find it very strange that this didn't show up during the
>> > regtest.
>> >
>> > To fix this, I had to uglify range_based_for_with_init_p to also check for 
>> > a ?.
>> > Yuck.
>>
>> Perhaps cp_parser_skip_to_closing_parenthesis_1 should handle balanced
>> ?: like ()/[]/{}.
>
> Good point.  Clearly there's a difference between ?: and e.g. () because : can
> stand alone--e.g. in asm (: "whatever"), labels, goacc arrays like a[0:N], and
> so on.  The following seems to work well, and is certainly less ugly than the
> previous version.
>
> +       case CPP_QUERY:
> +         if (!brace_depth)
> +           ++condop_depth;
> +         break;
> +
> +       case CPP_COLON:
> +         if (!brace_depth && condop_depth > 0)
> +           condop_depth--;
> +         break;

Since, as you say, colons can appear in more places, maybe we only
want to adjust condop_depth when all the other depths are 0, not just
brace_depth.

Jason

Reply via email to