c++: fix parsing with auto(x) at block scope [PR112482]
commit1ae71269890f532a2bb06b84fc49f474c16e230d
authorMarek Polacek <polacek@redhat.com>
Thu, 14 Dec 2023 17:01:21 +0000 (14 12:01 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 14 Dec 2023 21:39:51 +0000 (14 16:39 -0500)
tree9d1df936d0e0e4cb7e8fda0cf148dc8cbb16d5db
parent5fa27d9f8c4bec65887654e374146926d76690b0
c++: fix parsing with auto(x) at block scope [PR112482]

This is sort of like r14-5514, but at block scope.  Consider

  struct A { A(int, int); };
  void
  g (int a)
  {
    A bar(auto(a), 42); // not a fn decl
  }

where we emit error: 'auto' parameter not permitted in this context
which is bogus -- bar doesn't declare a function, so the auto is OK,
but we don't know it till we've seen the second argument.  The error
comes from grokdeclarator invoked just after we've parsed the auto(a).

A possible approach seems to be to delay the auto parameter checking
and only check once we know we are indeed dealing with a function
declaration.  For tparms, we should still emit the error right away.

PR c++/112482

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Do not issue the auto parameter error while
tentatively parsing a function parameter.
* parser.cc (cp_parser_parameter_declaration_clause): Check it here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/auto-fncast15.C: New test.
gcc/cp/decl.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp23/auto-fncast15.C [new file with mode: 0644]