[PATCH,c++] fix PR 4452{2,3}, autocorrect colon to scopes when appropriate
Nathan Froyd
froydnj@codesourcery.com
Thu Dec 9 16:01:00 GMT 2010
On Thu, Dec 09, 2010 at 04:13:06PM +0100, Dodji Seketeli wrote:
> Nathan Froyd <froydnj@codesourcery.com> writes:
> > @@ -4553,6 +4559,16 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
> > template-id), nor a `::', then we are not looking at a
> > nested-name-specifier. */
> > token = cp_lexer_peek_nth_token (parser->lexer, 2);
> > +
> > + if (token->type == CPP_COLON
> > + && parser->colon_corrects_to_scope_p
> > + && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_NAME)
> > + {
> > + error_at (token->location,
> > + "found %<:%> in nested-name-specifier, expected %<::%>");
> > + token->type = CPP_SCOPE;
> > + }
> > +
>
> I wonder how this would behave if cp_parser_nested_name_specifier_opt is
> called during a tentative parse that should (silently) fail. In that
> case my understanding is we would issue an error message even though we
> are just parsing tentatively.
That's a good question. I know that this code gets hit when parsing
tenatively (see the testcase in PR 39859, probably also the testcases I
included with the patch). I don't know whether there's a case where we
could auto-correct, issue an error, fail, reparse with no
auto-correction, and succeed. Hopefully there's no cases where that
would happen; I don't think the auto-correct would be very useful if we
limited it to non-tenative parses.
> Also, I am thinking maybe enabling the auto-correcting by default and
> picking where not to enable it can let us allow ':' instead of :: in too
> many places. Perhaps we should rather disable auto-correcting by default
> and just enable it during the parsing of a simple-declaration. Maybe I
> am just being overly conservative :-)
I think the optimistic view (auto-correct always, turn it off when you
can't) is somewhat more feasible; there's only so many places in the
grammar where you can have `:' and only so many places where you'd want
to correct it.
-Nathan
More information about the Gcc-patches
mailing list