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

Reply via email to