From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: fix parsing with auto(x) [PR112410]
Date: Thu, 9 Nov 2023 19:07:03 -0500 [thread overview]
Message-ID: <1c680274-040d-40d7-b998-b100084c0ba5@redhat.com> (raw)
In-Reply-To: <20231109195835.429291-1-polacek@redhat.com>
On 11/9/23 14:58, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> -- >8 --
> Here we are wrongly parsing
>
> int y(auto(42));
>
> which uses the C++23 cast-to-prvalue feature, and initializes y to 42.
> However, we were treating the auto as an implicit template parameter.
>
> Fixing the auto{42} case is easy, but when auto is followed by a (,
> I found the fix to be much more involved. For instance, we cannot
> use cp_parser_expression, because that can give hard errors. It's
> also necessary to disambiguate 'auto(i)' as 'auto i', not a cast.
> auto(), auto(int), auto(f)(int), auto(*), auto(i[]), auto(...), etc.
> are all function declarations. We have to look at more than one
> token to decide.
Yeah, this is a most vexing parse problem. The code is synthesizing
template parameters before we've resolved whether the auto is a
decl-specifier or not.
> In this fix, I'm (ab)using cp_parser_declarator, with member_p=false
> so that it doesn't commit. But it handles even more complicated
> cases as
>
> int fn (auto (*const **&f)(int) -> char);
But it doesn't seem to handle the extremely vexing
struct A {
A(int,int);
};
int main()
{
int a;
A b(auto(a), 42);
}
I think we need to stop synthesizing immediately when we see RID_AUTO,
and instead go back after we successfully parse a declaration and
synthesize for any autos we saw along the way. :/
Jason
next prev parent reply other threads:[~2023-11-10 0:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 19:58 Marek Polacek
2023-11-10 0:07 ` Jason Merrill [this message]
2023-11-11 1:13 ` [PATCH v2] " Marek Polacek
2023-11-14 2:26 ` Jason Merrill
2023-11-14 15:58 ` Marek Polacek
2023-11-14 22:27 ` Jason Merrill
2023-11-15 22:24 ` [PATCH v3] " Marek Polacek
2023-11-15 23:18 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1c680274-040d-40d7-b998-b100084c0ba5@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).