From patchwork Wed Sep 11 00:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1983587 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bMCw9fsH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4X3M7v0z77z1y1S for ; Wed, 11 Sep 2024 10:36:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAFD03858417 for ; Wed, 11 Sep 2024 00:36:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 022423858C98 for ; Wed, 11 Sep 2024 00:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 022423858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 022423858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726014936; cv=none; b=ERC5+Q0lPBPcqLxyeVdhAKGcu4453/C7at53l2yshdk5aztTtKL7f2gbFKOz+omHyrLi5bl3/aVSyh6IjXiwOwF4c9oq21+8n28e2vqwde5pcxY/MkbE/e0dei1j981px/0AajfbT7VRjYx0hbRSNe1pNOFwx5iUHHsiDijqAO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726014936; c=relaxed/simple; bh=qMh70oblXPvMUPOXg7q24250sMcjCf6y5aPK8OXGpk4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nxsyetfWja36L7Tku9nHzdbOeV9sFohN4tN1rN9EB4lfg5ax9s/KBqQfo2MsiEId22oRpE/MPMEZ9TAoof2P+UyAytdO0gaUWtB3CDp35Zm9uB6alscTwLwOBkynJhpYB76jMWr8WvKxMemuo8ACq+NzMOGLDmqR/HeezeaPSk8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726014927; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Zk+Rio1BLXMMyWDrYd9IURDH2xqlvFatkTcZ6MGU5R0=; b=bMCw9fsHPHuXlJPcXjZVQQEfhzKVYhYPyQF5G/OueHeKbX2KW0E4pTf5THFY5BhlTEpjSp XHQskqGGzbZz5k3uR2f58x79JhML69b+kMeFNa7w5uCu+4kBavV2qSh1UMDadPzR979C3u AK4xKfKKBcqfDN4m3xzfvkHaoq2X8i0= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-W7CionOCPCmSgu-Iw5XOqQ-1; Tue, 10 Sep 2024 20:35:26 -0400 X-MC-Unique: W7CionOCPCmSgu-Iw5XOqQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6c35c59296bso15301836d6.1 for ; Tue, 10 Sep 2024 17:35:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726014925; x=1726619725; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zk+Rio1BLXMMyWDrYd9IURDH2xqlvFatkTcZ6MGU5R0=; b=GjrQEmRWvDr95ivN5XpXUr7/e0Ukt/xt20w/obcdTfRoCSRZQ4Kgk5rrlL1yo5B0nl U//Y6u9EhcFM393ohoIdKBwjWjiIOTDkLpuamI3Wy1XObdKvSWDiY9e6ZsmK4J+iOW03 zfGBC9Nevuv+gjEjaRnUQnlrOkRQ9csxXZ0zU0C8LRlkolBCWoB1XIHbz/Lv5OVvYwUm efx8EyzNL1UuUERC+Dg8A+qRgOXi308CnUWZbl42aaPa0vafsnwotDTbQlajp6SFTfve S3xu04Z/+xBrKOUT/K0nEMfaA5Z/QkgBcOsMyw741SGHimPqhpaAaGWpDG/mVIEFl4SC tbNA== X-Gm-Message-State: AOJu0YxfjE6y2sW6gQhhti1ZIOFahPuP9Zq4gJkxdz5SbjBkQWgYPW1Y xIJn3VWLusAqgN2maVTMHJhkITiWGIUD8qrSA3oMiJGcXP8sLXx7zCznlAqD0ljRajxLYHKHiSX 5n4LueYaFAYv3KiI/IV8ey7o/+sm4hSVAsrb+2jj5EjO2wpRA+fg9srDVqJjnQK4+oJ+5adN7OE Bk1AO88PIG23VoOzmHflB+Y146kTgiIW+7h3M7 X-Received: by 2002:a05:620a:4001:b0:7a9:a632:3fdd with SMTP id af79cd13be357-7a9a6324392mr821587085a.11.1726014925029; Tue, 10 Sep 2024 17:35:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAdRfpDdGuA/Oo+KGh5Z4iGTACvVkfB0nzilHqbeJmcqWjYfq2w5l83532aERWy8UcDZhkGg== X-Received: by 2002:a05:620a:4001:b0:7a9:a632:3fdd with SMTP id af79cd13be357-7a9a6324392mr821585185a.11.1726014924488; Tue, 10 Sep 2024 17:35:24 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a9a7948814sm359189585a.14.2024.09.10.17.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 17:35:24 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: decltype(auto) deduction of statement-expression [PR116418] Date: Tue, 10 Sep 2024 20:35:21 -0400 Message-ID: <20240911003521.2691563-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.540.g4c42d5ff28 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/backports? -- >8 -- r8-7538 for PR84968 made strip_typedefs_expr diagnose seeing STATEMENT_LIST, which effectively makes us reject statement-expressions noexcept-specifiers (we already diagnose them in template arguments at parse time). Later r11-7452 made decltype(auto) deduction do strip_typedefs_expr on the expression before deducing (as an implementation detail) and so ever since we inadvertently reject decltype(auto) deduction of a statement-expression. This patch just removes the diagnostic in strip_typedefs_expr; it doesn't seem like the right place for it. And it lets us accept more code using statement-expressions in various contexts. PR c++/116418 PR c++/84968 gcc/cp/ChangeLog: * tree.cc (strip_typedefs_expr) : Replace with ... : ... this non-diagnosing early exit. gcc/testsuite/ChangeLog: * g++.dg/eh/pr84968.C: No longer expect ah ahead of time diagnostic for the statement-expresssion. Instantiate the template and expect an incomplete type error instead. * g++.dg/ext/stmtexpr26.C: New test. --- gcc/cp/tree.cc | 5 ++--- gcc/testsuite/g++.dg/eh/pr84968.C | 4 +++- gcc/testsuite/g++.dg/ext/stmtexpr26.C | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/stmtexpr26.C diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 31ecbb1ac79..a150a91f2fa 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -2011,9 +2011,8 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) case LAMBDA_EXPR: return t; - case STATEMENT_LIST: - error ("statement-expression in a constant expression"); - return error_mark_node; + case STMT_EXPR: + return t; default: break; diff --git a/gcc/testsuite/g++.dg/eh/pr84968.C b/gcc/testsuite/g++.dg/eh/pr84968.C index 23c49f477a8..a6e21914eed 100644 --- a/gcc/testsuite/g++.dg/eh/pr84968.C +++ b/gcc/testsuite/g++.dg/eh/pr84968.C @@ -9,7 +9,9 @@ struct S { void a() try { } catch (int () - noexcept (({ union b a; true; }))) // { dg-error "constant" } + noexcept (({ union b a; true; }))) // { dg-error "'b a' has incomplete type" } { } }; + +template void S::a(); // { dg-message "required from here" } diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr26.C b/gcc/testsuite/g++.dg/ext/stmtexpr26.C new file mode 100644 index 00000000000..498dd12ef10 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/stmtexpr26.C @@ -0,0 +1,10 @@ +// PR c++/116418 +// { dg-do compile { target c++14 } } + +void foo (); +template +void bar () +{ + decltype(auto) v = ({ foo (); 3; }); +} +