From patchwork Sun Apr 5 14:56:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 132715 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BFE2E4BA23D6 for ; Sun, 5 Apr 2026 14:56:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFE2E4BA23D6 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=fc8/3ynr X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by sourceware.org (Postfix) with ESMTPS id 421804BA2E20 for ; Sun, 5 Apr 2026 14:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 421804BA2E20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 421804BA2E20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775400970; cv=none; b=gHM9v+ZTruQWE0gtu6xBsZyoaBfeliCWG0EWeR1h1K8joMKdZSbxSXKEJ+Xn5itiuKiI4RYlbtt9wqec2x2ciImNivnfwwyhgihys7upBWej5ntObHC0ghHdAz6AXQyMreipwWmD2y2am1JgeD3QxDSTOj6tvRzpsep2bWvRVYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775400970; c=relaxed/simple; bh=3Bc973kqAHbCHfVLWdyBUmDTINb3/f8y/nSUtTTGskA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=oD6mM5Qq3XUbB4/re7iXGnW0gn8Nnf1nR4g2rp0s3WPSHJ/4o9yWwl1G1ooyKNYWmenbIzClI0K6XoiOHwuU6V/k7SsG6Nx7So6KMuMHyyvS6DvaI5M3iXHa5k+bHV+8u6QD/zmkyfgeHFuijifWbMbzrHPBJih94wHqDkbhN+E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 421804BA2E20 Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-35d9603c2c0so823065a91.2 for ; Sun, 05 Apr 2026 07:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775400969; x=1776005769; darn=gcc.gnu.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=uDlH9OCAAQHRlVMrquEhqJn5dJJ9cfhFGwrOCy1GL64=; b=fc8/3ynrqYDL+oqiDuu+ORn86/AeH2MT9PlYbpJ0mbaubPx41WSLpT6/9YGaXAQz9J /oXBuZOdaLk3f4ntKFD4Fr4Kf8OBmZ6s5Vb4oLTG9plKCrQpbmzjWfEKvgrJMo3Ovb4W lDxm2l5V+33njfiAoL+zFo3xrBBG14PoGy0KDLF6mpMWA2agxz/dOOgRBGHeJCdHWIv2 1RTmGVujDvnYQ3jvx+2mxiIW0QtzqcMRWNeICfUT9Ol5v9aROunnP3i9UztdTOf6FBr1 3q1Zh+yzwG4B38ve6G4yW59v4jM1TUMYyumucZgyY/22ZsrFk08mhbnXnDqSRc3INQjS LGkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775400969; x=1776005769; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uDlH9OCAAQHRlVMrquEhqJn5dJJ9cfhFGwrOCy1GL64=; b=Pkkj5AgQGbu1fCRfCk+HYoJ+4KEhX2hiKhg1OjLneQ+765UxNS/kOa//bWEJLnhlRd 1dCVDqfiTGWguYQ+R943PD0BO1FM1Ug1e33z+JK/tfCPZxa+124sPmtqNBbXO/gxqoQe GjYNGlbLT3iSty8sCMbTwtvrODCJxxuMw3tGpuWiPighTFgNa933eEcF0qhp7BAolWnj HnUQRVq6vBgyK+7nhjuV0trIuCfmHBWAtTf/r78547+ZjRJ3Erus+4swcTCscjTUAk1n C05HF9MQc9l64IPeJpza/4pNJNaTjNFkXStIoEdUrX9U6Q/O4Bv+naEcqw4X23g6A+am iKGg== X-Gm-Message-State: AOJu0YzxJDq/fmvwavbV9g8WJwfwWzumnIIuECd+QkX9YnN9WbuaU1N4 IxkCLt8xcqfLaB2J1rT208jR5r49rjaq0EsyT27ftfO7atj2EzyL0qdUg4EM9A== X-Gm-Gg: AeBDieupUuUmTHPIaBb3qWaV15CgIc6q/VkNBNiJGFEKPrZ7WayuPDukxUEZBv+lmUR PYlHZDxj0sGWZ1lRxhmeAnBbzpvQBjeEU7mKUmEzgVCCIYmUPUGl++2UyR+09tM2pTOlZob7Ap9 qCVBz5b2TM7yjfZWk7w2EkHtdYdVnbLC+uWoo/g6G+oKXujPlgI5lgVE7Xh+SvAOc6kpbK7r2/p HZLnOR2dfmq65N253TWm8Koe3EMxh+5Aqolt3k5dccOctX3hrbmHqyztsawgmuUN8FGcH7n38lo gpKPC7EAbkJT2yt2mq1C+YcYnToF0z2ZEfY6rD/URhqWleXb0ZIPrOoYIPyXvTydmJaiSqhussg bWfWiR4G2YhhlgKQWrhi7am/jxbsD3lkpyAmUBr0M8EvBJUirYNC1AuOwURz36o089boABqQkop uQsvq7x09SyUCrAV8AY7+a4bFvmod/lyQDdg1wAD90ETS90u9JOzXSqLtMGXw7q1YOg05LXXxrl L0= X-Received: by 2002:a17:903:186:b0:2b2:5822:7a65 with SMTP id d9443c01a7336-2b28192dd24mr56629455ad.8.1775400969083; Sun, 05 Apr 2026 07:56:09 -0700 (PDT) Received: from Thaum.localdomain (163-53-146-3.ip4.superloop.au. [163.53.146.3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b27472d618sm107764115ad.12.2026.04.05.07.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Apr 2026 07:56:08 -0700 (PDT) Date: Mon, 6 Apr 2026 00:56:02 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] c++/modules: Fix propagating noexcept for templates [PR124785] Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 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 and regtested on x86_64-pc-linux-gnu, OK for trunk/15? -- >8 -- We triggered a checking assertion because when propagating deduced noexcept, we were updating the type of the existing TEMPLATE_DECL but not the type of its DECL_TEMPLATE_RESULT, violating assumptions made later on during modules streaming. But actually there was nothing to propagate here anyway, these declarations are identical, so this patch also fixes the condition for checking whether we need to propagate anything. And so now I don't think there is ever a case we should have a noexcept-spec to propagate for a TEMPLATE_DECL, so add an assertion to validate this. PR c++/124785 gcc/cp/ChangeLog: * module.cc (trees_in::is_matching_decl): Narrow condition for when noexcept propagation occurs; assert that we don't propagate noexcept-specs for TEMPLATE_DECLs. gcc/testsuite/ChangeLog: * g++.dg/modules/noexcept-5.h: New test. * g++.dg/modules/noexcept-5_a.C: New test. * g++.dg/modules/noexcept-5_b.C: New test. * g++.dg/modules/noexcept-5_c.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 4 +++- gcc/testsuite/g++.dg/modules/noexcept-5.h | 4 ++++ gcc/testsuite/g++.dg/modules/noexcept-5_a.C | 7 +++++++ gcc/testsuite/g++.dg/modules/noexcept-5_b.C | 7 +++++++ gcc/testsuite/g++.dg/modules/noexcept-5_c.C | 11 +++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/noexcept-5.h create mode 100644 gcc/testsuite/g++.dg/modules/noexcept-5_a.C create mode 100644 gcc/testsuite/g++.dg/modules/noexcept-5_b.C create mode 100644 gcc/testsuite/g++.dg/modules/noexcept-5_c.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index a8517569a1b..8b820f97fee 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -12619,12 +12619,14 @@ trees_in::is_matching_decl (tree existing, tree decl, bool is_typedef) tree d_spec = TYPE_RAISES_EXCEPTIONS (d_type); if (DECL_MAYBE_DELETED (e_inner) || DEFERRED_NOEXCEPT_SPEC_P (e_spec)) { - if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec) + if (!(DECL_MAYBE_DELETED (d_inner) + || DEFERRED_NOEXCEPT_SPEC_P (d_spec)) || (UNEVALUATED_NOEXCEPT_SPEC_P (e_spec) && !UNEVALUATED_NOEXCEPT_SPEC_P (d_spec))) { dump (dumper::MERGE) && dump ("Propagating instantiated noexcept to %N", existing); + gcc_checking_assert (existing == e_inner); TREE_TYPE (existing) = d_type; /* Propagate to existing clones. */ diff --git a/gcc/testsuite/g++.dg/modules/noexcept-5.h b/gcc/testsuite/g++.dg/modules/noexcept-5.h new file mode 100644 index 00000000000..78d91322a1a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/noexcept-5.h @@ -0,0 +1,4 @@ +// PR c++/124785 +template struct Iterator { + constexpr friend auto operator<=>(const Iterator&, const Iterator&) = default; +}; diff --git a/gcc/testsuite/g++.dg/modules/noexcept-5_a.C b/gcc/testsuite/g++.dg/modules/noexcept-5_a.C new file mode 100644 index 00000000000..72085717e60 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/noexcept-5_a.C @@ -0,0 +1,7 @@ +// PR c++/124785 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fmodules" } +// { dg-module-cmi M:A } + +export module M:A; +#include "noexcept-5.h" diff --git a/gcc/testsuite/g++.dg/modules/noexcept-5_b.C b/gcc/testsuite/g++.dg/modules/noexcept-5_b.C new file mode 100644 index 00000000000..928980b6c1d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/noexcept-5_b.C @@ -0,0 +1,7 @@ +// PR c++/124785 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fmodules" } +// { dg-module-cmi M:B } + +export module M:B; +#include "noexcept-5.h" diff --git a/gcc/testsuite/g++.dg/modules/noexcept-5_c.C b/gcc/testsuite/g++.dg/modules/noexcept-5_c.C new file mode 100644 index 00000000000..d9349147766 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/noexcept-5_c.C @@ -0,0 +1,11 @@ +// PR c++/124785 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fmodules -fdump-lang-module-alias" } +// { dg-module-cmi M } + +export module M; +export import :A; +export import :B; + +// The noexcept-specifiers are equivalent, no need to merge. +// { dg-final { scan-lang-dump-not {Propagating instantiated noexcept} module } }