From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DF8923858013; Thu, 9 Dec 2021 16:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF8923858013 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103401] [11/12 Regression] gcc accepts decltype(auto(0)) as the parameter of the function Date: Thu, 09 Dec 2021 16:49:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2021 16:49:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103401 --- Comment #5 from CVS Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:6a071b2d40a1078b4029c2b77ef29ffca4e7050c commit r12-5860-g6a071b2d40a1078b4029c2b77ef29ffca4e7050c Author: Marek Polacek Date: Thu Nov 25 09:08:03 2021 -0500 c++: Handle auto(x) in parameter-declaration-clause [PR103401] In C++23, auto(x) is valid, so decltype(auto(x)) should also be valid, so void f(decltype(auto(0))); should be just as void f(int); but currently, everytime we see 'auto' in a parameter-declaration-claus= e, we try to synthesize_implicit_template_parm for it, creating a new temp= late parameter list. The code above actually has us calling s_i_t_p twice; once from cp_parser_decltype_expr -> cp_parser_postfix_expression which fails and then again from cp_parser_decltype_expr -> cp_parser_expressi= on. So it looks like we have f and we accept ill-formed code. This shows that we need to be more careful about synthesizing the implicit template parameter. [dcl.spec.auto.general] says that "A placeholder-type-specifier of the form type-constraintopt auto can be used as a decl-specifier of the decl-specifier-seq of a parameter-declaration of a function declaration or lambda-expression..." so this patch turns off auto_is_... after we've parsed the decl-specifier-seq. That doesn't quite cut it yet though, because we also need to handle an auto nested in the decl-specifier: void f(decltype(new auto{0})); therefore the cp_parser_decltype change. To accept "sizeof(auto{10})", the cp_parser_type_id_1 hunk only gives a hard error when we're not parsing tentatively. The cp_parser_parameter_declaration hunk broke lambda-generic-85713-2.C= but I think the error we issue with this patch is in fact correct, and clan= g++ agrees. The r11-1913 change is OK: we need to make sure that we see '(auto)' af= ter decltype to go ahead with 'decltype(auto)'. PR c++/103401 gcc/cp/ChangeLog: * parser.c (cp_parser_decltype): Clear auto_is_implicit_function_template_parm_p. (cp_parser_type_id_1): Give errors only when !cp_parser_simulate_error. (cp_parser_parameter_declaration): Clear auto_is_implicit_function_template_parm_p after parsing the decl-specifier-seq. (cp_parser_sizeof_operand): Clear auto_is_implicit_function_template_parm_p. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-85713-2.C: Add dg-error. * g++.dg/cpp1y/pr60054.C: Adjust dg-error. * g++.dg/cpp1y/pr60332.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-2.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-3.C: Likewise. * g++.dg/cpp2a/concepts-pr84979.C: Likewise. * g++.dg/cpp23/auto-fncast7.C: New test. * g++.dg/cpp23/auto-fncast8.C: New test. * g++.dg/cpp23/auto-fncast9.C: New test.=