From patchwork Tue Sep 17 12:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1986403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=tey23rxsjton5kop5bydp3vc5ylkyjkg header.b=gs8G++Ab; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=eckzGHPV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X7LMB66v0z1y1m for ; Tue, 17 Sep 2024 22:14:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6525E385840A for ; Tue, 17 Sep 2024 12:14:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a2-22.smtp-out.eu-west-1.amazonses.com (a2-22.smtp-out.eu-west-1.amazonses.com [54.240.2.22]) by sourceware.org (Postfix) with ESMTPS id 241A13858D26 for ; Tue, 17 Sep 2024 12:14:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 241A13858D26 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 241A13858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.2.22 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726575271; cv=none; b=J0MDAyb14qtPQrROzF/zEabpUtbez9UuhewGeWOtXdFqjAAmrWlcFuxIzhdmAH7DUZy67On0SvvHUK+8TkztE7+ggOs1WXtBGj63xK54kja5v9uCuARkyJfTlj7pgFyYJTNuKW2TJL8JTnPOT0LvgcbMtnDu+LgcNgGSl/psocU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726575271; c=relaxed/simple; bh=9nF4uDz+SqjTEskgXlydGSzaiLcY+6IsomWu5bvCJTk=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=d3nWcm/ULfkZzc7ZqYg3oROP0ddXxjUzkTYC0/ll7tW/zEIp5Nd7L1bRJotfKPGvMpZMVrmU3jABUzPlZXA2DemOnPmnUn2eophlW1DjM7V0skSw7VSJuZUQUF7R9zYjmxgyRhxaRqM8dWxiTDZT1/bDBKCQqbPB0M1oAMS01fo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=tey23rxsjton5kop5bydp3vc5ylkyjkg; d=nasilyan.com; t=1726575268; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=9nF4uDz+SqjTEskgXlydGSzaiLcY+6IsomWu5bvCJTk=; b=gs8G++AbdPwjzeuu/jPKERS/hGOmYezsoZWA+u24kpmbuZqv9JE+BJLzJAtBvOA5 JHALDT/5BOQ/CetjZkPLUukRkpmfxjC7ModM+fmBgG6ecdojJONK1qinIEdG5/yjSfh nj8R8qLjVhwuZxf651ClcY3tDG2UYRYH5ZAihJko= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726575268; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=9nF4uDz+SqjTEskgXlydGSzaiLcY+6IsomWu5bvCJTk=; b=eckzGHPVeK9hFxvYVdp7OE+58Q07fegdNIAa9UA6xJGbfv6VduVkVbu29kJRZ6Pf N0mAViQeqDJc92SY+gs9kz3yYF/3Ttym1ndJsJzKeQzKQi933C13WymtH+tux4QIYbK ujKq7Z/36yeYt0vA0V7YxHQfV3B/5BWFJK87a2+0= Subject: [PATCH] c++: Avoid "infinite parsing" because of cp_parser_decltype [PR114858] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Tue, 17 Sep 2024 12:14:28 +0000 Mime-Version: 1.0 References: <20240917121424.17543-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHbCPsjgnbtbyjTRTWojm0wE7UFKQ== Thread-Topic: [PATCH] c++: Avoid "infinite parsing" because of cp_parser_decltype [PR114858] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1726575267 Message-ID: <01020191ffe7d291-0ceb3852-2428-49cc-97c5-7c6e8072ec43-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.09.17-54.240.2.22 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The invalid test case in this PR highlights a bad interaction between the tentative_firewall and error recovery in cp_parser_decltype: the firewall makes cp_parser_skip_to_closing_parenthesis a no-op, and the parser does not make any progress, running "forever". This patch calls cp_parser_commit_to_tentative_parse before initiating error recovery. Successfully tested on x86_64-pc-linux-gnu. PR c++/114858 gcc/cp/ChangeLog: * parser.cc (cp_parser_decltype): Commit tentative parse before initiating error recovery. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/decltype10.C: Adjust test expectation. * g++.dg/cpp2a/pr114858.C: New test. --- gcc/cp/parser.cc | 3 +++ gcc/testsuite/g++.dg/cpp0x/decltype10.C | 2 ++ gcc/testsuite/g++.dg/cpp2a/pr114858.C | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr114858.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 4dd9474cf60..3a7c5ffe4c8 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -17508,6 +17508,9 @@ cp_parser_decltype (cp_parser *parser) /* Parse to the closing `)'. */ if (expr == error_mark_node || !parens.require_close (parser)) { + /* Commit to the tentative_firewall so we actually skip to the closing + parenthesis. */ + cp_parser_commit_to_tentative_parse (parser); cp_parser_skip_to_closing_parenthesis (parser, true, false, /*consume_paren=*/true); expr = error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype10.C b/gcc/testsuite/g++.dg/cpp0x/decltype10.C index fe7247269f5..bd606e325d4 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype10.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype10.C @@ -7,3 +7,5 @@ template struct A }; template int A::i(decltype (A::i; // { dg-error "expected" } + +// { dg-excess-errors "" } diff --git a/gcc/testsuite/g++.dg/cpp2a/pr114858.C b/gcc/testsuite/g++.dg/cpp2a/pr114858.C new file mode 100644 index 00000000000..6ffde4c3a2c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/pr114858.C @@ -0,0 +1,25 @@ +// PR c++/114858 +// { dg-do compile { target c++20 } } +// { dg-timeout 2 } + +template void g(F); +template +auto h(A &&... a) -> decltype( + decltype(g< // { dg-error "expected primary-expression" } + decltype(g)(a)...) +{ + h([] {}); +} + +int main() { + h(); + return 0; +} + +// { dg-excess-errors "" }