]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: auto in trailing-return-type in parameter [PR117778]
authorMarek Polacek <polacek@redhat.com>
Wed, 29 Jan 2025 20:58:38 +0000 (15:58 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 14 May 2025 14:37:16 +0000 (10:37 -0400)
commit52202e42919d0d95c13889bed9e69b954e4376af
treea130e5fa23e986bfa759db997ec9a3e34bdc8122
parent9ce96b683a40a12299c1d0e02727e747c00ad883
c++: auto in trailing-return-type in parameter [PR117778]

This PR describes a few issues, both ICE and rejects-valid, but
ultimately the problem is that we don't properly synthesize the
second auto in:

  int
  g (auto fp() -> auto)
  {
    return fp ();
  }

since r12-5860, which disabled auto_is_implicit_function_template_parm_p
in cp_parser_parameter_declaration after parsing the decl-specifier-seq.

If there is no trailing auto, there is no problem.

So we have to make sure auto_is_implicit_function_template_parm_p is
properly set when parsing the trailing auto.  A complication is that
one can write:

  auto f (auto fp(auto fp2() -> auto) -> auto) -> auto;
                                      ~~~~~~~

where only the underlined auto should be synthesized.  So when we
parse a parameter-declaration-clause inside another
parameter-declaration-clause, we should not enable the flag.  We
have no flags to keep track of such nesting, but I think I can walk
current_binding_level to see if we find ourselves in such an unlikely
scenario.

PR c++/117778

gcc/cp/ChangeLog:

* parser.cc (cp_parser_late_return_type_opt): Maybe override
auto_is_implicit_function_template_parm_p.
(cp_parser_parameter_declaration): Move a make_temp_override below.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-117778.C: New test.
* g++.dg/cpp2a/abbrev-fn2.C: New test.
* g++.dg/cpp2a/abbrev-fn3.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit e6e40cb7459c9b21b291fe28e46cd4ebcd924dff)
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp1y/lambda-generic-117778.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/abbrev-fn2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/abbrev-fn3.C [new file with mode: 0644]