This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch] PR 89875 ("[7/8/9/10 Regression] invalid typeof reference to a member of an incomplete struct accepted at function scope")
- From: Jason Merrill <jason at redhat dot com>
- To: Paolo Carlini <paolo dot carlini at oracle dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 28 May 2019 10:47:00 -0400
- Subject: Re: [C++ Patch] PR 89875 ("[7/8/9/10 Regression] invalid typeof reference to a member of an incomplete struct accepted at function scope")
- References: <7d7ad6b4-4877-98e0-9daa-a649089f12fa@oracle.com>
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