From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8BB5D3858000; Tue, 12 Dec 2023 00:37:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BB5D3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702341470; bh=sskncxChe3Me7DEELSrpo0eIwOmvsZ0Epc1mtSJohuQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lLERIGR9jvD/Shf13o3NICA4FQPTFa8XqPa3f2rXGjW6KsufA+MfSNJa14mhgAhSH oQZMUeHa3j9S8GB/LaD/ADCXH1qUvRFFt1GhJubZVJjeOPHZNat46QHP1HRqvVnRA3 gARA+5R2qOYjdAUKoPXQkDteQWZgMmJ1RtV1ADXA= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112410] error when auto(x) is used in a variable initializer Date: Tue, 12 Dec 2023 00:37:50 +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: 14.0 X-Bugzilla-Keywords: rejects-valid 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: --- 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112410 --- Comment #6 from GCC Commits --- The releases/gcc-13 branch has been updated by Marek Polacek : https://gcc.gnu.org/g:60979215517629400902938b1c5666f97d0653cf commit r13-8147-g60979215517629400902938b1c5666f97d0653cf Author: Marek Polacek Date: Thu Nov 9 12:25:25 2023 -0500 c++: fix parsing with auto(x) [PR112410] 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. This patch rectifies that by undoing the implicit function template modification. In the test above, we should notice that the parameter list is ill-formed, and since we've synthesized an implicit template parameter, we undo it by calling abort_fully_implicit_template. Then, we'll parse the "(auto(42))" as an initializer. PR c++/112410 gcc/cp/ChangeLog: * parser.cc (cp_parser_direct_declarator): Maybe call abort_fully_implicit_template if it turned out the parameter li= st was ill-formed. gcc/testsuite/ChangeLog: * g++.dg/cpp23/auto-fncast13.C: New test. * g++.dg/cpp23/auto-fncast14.C: New test. (cherry picked from commit 70060dadfbf0d0af5f4cab5f3aff3223a4523606)=