[C++ Patch] PR 89875 ("[7/8/9/10 Regression] invalid typeof reference to a member of an incomplete struct accepted at function scope")
Jason Merrill
jason@redhat.com
Wed May 29 16:22:00 GMT 2019
On 5/28/19 4:44 PM, Paolo Carlini wrote:
> Hi,
>
> On 28/05/19 16:47, Jason Merrill wrote:
>> 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.
>
> Today I spent quite a bit of time on this and eventually decided to
> follow the example of decltype as closely as possible. Then I started
> tweaking those drafts which laready passed the testsuite and after a
> while ended up with the below, rather close to the current code, in
> fact. Testing !cp_parser_error_occurred and in case calling
> cp_parser_abort_tentative_parse by hand (closer to the decltype example)
> also works. What do you think? Thanks, Paolo.
OK.
Jason
More information about the Gcc-patches
mailing list