From patchwork Tue Jun 2 21:59:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 136332 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 819394BA2E2C for ; Tue, 2 Jun 2026 22:00:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 819394BA2E2C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DT4X/WBU 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.133.124]) by sourceware.org (Postfix) with ESMTP id 50A264BA2E12 for ; Tue, 2 Jun 2026 21:59:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50A264BA2E12 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 50A264BA2E12 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780437591; cv=none; b=qmR2Kmirn55ULfGYGSR2l0hVCKORIJ5awNYIKnLpw0s56EArrHcwvMoQPZ2gym6MXv6994Xw4Qd0KnDh3nrhwsFDhLZhzAVihP6JxXqkZNR0wROyl7YCRqQuBlmNwxciNnOKDtn8LBsFz4OuMuVQBbfh4A5Eq2lYffMDtPGLAx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780437591; c=relaxed/simple; bh=DVuaISTAyr8v7VzMnr/vMZyqw/rDfWHhu3LCa3re7Fc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Vk9tiCr57jTwHA4hXJz4Wwg+asc3azeLFbUncgUy0nNJKpCkoAgKAglMoZ3qlnmUiTOowDHVigtbDnVshsGvKCo6PZ7o1yoObg9E9e8n0uUbjDVsr57feDVumWV8GdsgY4ATBefn8c64nIiKE4dukpyBdkOnFiAIaDDPAaTeKAQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DT4X/WBU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50A264BA2E12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780437591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QAQDYa0UMC1LtjXF30p9gIpojvB348u+pmhkbB+Lvbc=; b=DT4X/WBU694Tns8oDHwR6ysN1IfIJTsjkNAX+A5nuS9nvVlqclUpjWb3+xbHw4tP5kTQPq 14LwlW9H2t6cq9LQT/eS2Ri7ZHchMq3D2kG6Ao26JdDIZZSIvXeEFmpOKa6CpAwUg6ZRoK T/QOTjN8i3EsPaSXAW7h41pTIPO/jnE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-k2EVmJrCOrSEmWxSoh7rQw-1; Tue, 02 Jun 2026 17:59:49 -0400 X-MC-Unique: k2EVmJrCOrSEmWxSoh7rQw-1 X-Mimecast-MFC-AGG-ID: k2EVmJrCOrSEmWxSoh7rQw_1780437588 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 414321956094 for ; Tue, 2 Jun 2026 21:59:48 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.81.145]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A30111956095; Tue, 2 Jun 2026 21:59:47 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE in tsubst_expr with comma expr [PR125539] Date: Tue, 2 Jun 2026 17:59:43 -0400 Message-ID: <20260602215943.1119054-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GYb4xFfm6kyQNyWreYh5USCkIjvD2n5qUEBUf7tXT50_1780437588 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.0 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_BLOCKED, RCVD_IN_HOSTKARMA_W, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches? -- >8 -- Here we crash because a TARGET_EXPR gets into tsubst_expr with something like: template constexpr static A a = (A{}, A{}); Pre r14-4796, when we had tsubst_copy, we didn't crash because we had an early exit when substituting with args=NULL_TREE. tsubst_expr deliberately doesn't have that early exit. Note that template constexpr static A a = A{}; works because expand_aggr_init_1 sees a COMPOUND_LITERAL_P and does the early exit without calling expand_default_init. But with a COMPOUND_EXPR we don't take that path. The TARGET_EXPR is created via check_initializer -> build_aggr_init_full_exprs -> build_aggr_init -> expand_aggr_init_1 -> expand_default_init -> ocp_convert -> build_cplus_new -> build_target_expr. I tried adjusting the big and ugly check in check_initializer before build_aggr_init_full_exprs but that didn't work out. I also tried avoiding the call to ocp_convert but that broke some reflection tests. But avoiding the call to build_cplus_new seems to work. PR c++/125539 gcc/cp/ChangeLog: * cvt.cc (ocp_convert): Don't call build_cplus_new in a template. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ89.C: New test. --- gcc/cp/cvt.cc | 4 ++- gcc/testsuite/g++.dg/cpp1y/var-templ89.C | 32 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ89.C base-commit: ee7d0c7b4102b8ef0bcaa725c75e141248b774cb diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index b1176317d99..571f2e64d03 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -985,7 +985,9 @@ ocp_convert (tree type, tree expr, int convtype, int flags, type, flags, complain); } if (ctor) - return build_cplus_new (type, ctor, complain); + return (processing_template_decl + ? ctor + : build_cplus_new (type, ctor, complain)); } if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ89.C b/gcc/testsuite/g++.dg/cpp1y/var-templ89.C new file mode 100644 index 00000000000..5f98a95580c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ89.C @@ -0,0 +1,32 @@ +// PR c++/125539 +// { dg-do compile { target c++14 } } + +struct A {}; +struct B { int i; }; +constexpr void foo () {} + +template +constexpr static A a1 = (foo (), A {}); +template +constexpr static A a2 = (A{}, A{}); +template +constexpr static A a3 = A{}; +template +constexpr static A a4 = {}; +template +constexpr static A a5{}; +template +constexpr static A a6 = (A{}, A{}, A{}, A{}, A{}, A{}, A{}); +template +constexpr static B b1 = B{N}; +template +constexpr static B b2 = (B{N}, B{N}); + +template const A a1; +template const A a2; +template const A a3; +template const A a4; +template const A a5; +template const A a6; +template const B b1<42>; +template const B b2<42>;