On 5/10/19 10:29 AM, Paolo Carlini wrote:
Hi,
a while ago Martin noticed that an unintended consequence of an old
tweak of mine - which avoided redundant error messages emitted from
cp_parser_init_declarator - is that, in some cases, we started accepting
ill-formed typeofs. Luckily, decltype isn't affected and that points to
the real issue: by the time that place in cp_parser_init_declarator is
reached, for a decltype version we already emitted a correct error
message. Thus I think the right way to fix the problem is simply
committing to tentative parse when, toward the end of
cp_parser_sizeof_operand we know that we must be looking at a (possibly
ill-formed) expression. Tested x86_64-linux.
The problem with calling cp_parser_commit_to_tentative_parse here is
that the tentative parse you're committing to is for the enclosing
scope, which is trying to decide whether e.g. we're parsing a
declaration or expression. If the operand of typeof is a well-formed
expression, and the larger context is an expression, this will break.
Better, I think, to commit and re-parse only if you actually encounter
an error.
Alternately, cp_parser_decltype_expr deals with this by using a
tentative firewall and CPP_DECLTYPE; cp_parser_sizeof_operand could do
the same, but that seems like a bigger hammer.
Jason