{"id":2219981,"url":"http://patchwork.ozlabs.org/api/patches/2219981/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/adJkz7LoEuf_78_o@Thaum.localdomain/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<adJkz7LoEuf_78_o@Thaum.localdomain>","list_archive_url":null,"date":"2026-04-05T13:34:07","name":"c++/modules: Only mark namespace-scope entities as exported [PR124781]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a30f85bdf8222ff66dc4f59fe48fb8b737aea08d","submitter":{"id":85216,"url":"http://patchwork.ozlabs.org/api/people/85216/?format=json","name":"Nathaniel Shead","email":"nathanieloshead@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/adJkz7LoEuf_78_o@Thaum.localdomain/mbox/","series":[{"id":498785,"url":"http://patchwork.ozlabs.org/api/series/498785/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=498785","date":"2026-04-05T13:34:07","name":"c++/modules: Only mark namespace-scope entities as exported [PR124781]","version":1,"mbox":"http://patchwork.ozlabs.org/series/498785/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219981/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219981/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=aoO5uD7b;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=aoO5uD7b","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.216.45"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fpYNn42bQz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 23:34:44 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D75FD4BA2E36\n\tfor <incoming@patchwork.ozlabs.org>; Sun,  5 Apr 2026 13:34:41 +0000 (GMT)","from mail-pj1-f45.google.com (mail-pj1-f45.google.com\n [209.85.216.45])\n by sourceware.org (Postfix) with ESMTPS id D9D6D4BA2E20\n for <gcc-patches@gcc.gnu.org>; Sun,  5 Apr 2026 13:34:14 +0000 (GMT)","by mail-pj1-f45.google.com with SMTP id\n 98e67ed59e1d1-35d9b4f93f0so791971a91.3\n for <gcc-patches@gcc.gnu.org>; Sun, 05 Apr 2026 06:34:14 -0700 (PDT)","from Thaum.localdomain ([163.53.146.3])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b2749cdc61sm111032745ad.80.2026.04.05.06.34.11\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sun, 05 Apr 2026 06:34:13 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D75FD4BA2E36","OpenDKIM Filter v2.11.0 sourceware.org D9D6D4BA2E20"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org D9D6D4BA2E20","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org D9D6D4BA2E20","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775396055; cv=none;\n b=JezhuolSlUAvZWKB4v6SZ3GZ/NB10fK95NtEurMxIUFK8/xp+NJ4fRV9IWiqKtLXZAzUi3a3ak9XbrNM+VjRo+686LrvDfhKR+rpolHXuus4LqXE/nAKRSSb5dpsK5rElCT4E+SfClNIRi0jMV+1oDnwvlDORL8jvo7kHkjWwMs=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775396055; c=relaxed/simple;\n bh=IHc8Ls6fqjp6zir01pgi28/CGM5r3OgRq+3e4bSmUKo=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=OQw95pcPNlq22Nw09jhNoCmAYwfmMZN/V6PP8sz+KGMFmSHitADoLeRMe7xN/Im/QRP2h40LTFvDx7Y2YNld8YXbNYB9cap0aKn193j3BW8SlE/YYwWhKO7AiGkRlymWYsSc7uzKbwwPDqpCgl8EFFJHhLlC6lZrxt1/12dzsy0=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775396054; x=1776000854; darn=gcc.gnu.org;\n h=content-disposition:mime-version:message-id:subject:cc:to:from:date\n :from:to:cc:subject:date:message-id:reply-to;\n bh=kYD5HlHZqDacLDfD6TXfab9q6FCp5Ug+Nbcfralfee0=;\n b=aoO5uD7bJQ/vVZsuqSsIC73CfVOzS/z80GQDLQsNfaBCodRnJiyQKu8RixCNqwK4vV\n 7k52zckdjL2KKSnU/fPsaSR3phvNdhL8qGvpposLOMsNKQ5iYRqWZ9E59iuJybwGmi0Y\n YrjPLfr1X/BYcqp93IiYtBceIFCw5ibexEzEOsqyF6iC2mBzHSoAbQz0wMA6LSgdpZqo\n pfeyyQDg/xcP3AIlyThNPUis32/hfqVT4dXi3VJO1dt7T6FqKPxFTSOVusCdTR1hwZk9\n 231JQx72CVpQ6goqr94gx/hkVJO+cpvg8XGWG4CKlAXp6q5GJDoNO0RrFJQSuY9sm3rd\n b8Zg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775396054; x=1776000854;\n h=content-disposition:mime-version:message-id:subject:cc:to:from:date\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=kYD5HlHZqDacLDfD6TXfab9q6FCp5Ug+Nbcfralfee0=;\n b=hvthTq1w0DiVV6bgrkIM8Dk+5uFTyHv9IQ9kefdRbnb0w5EHx/IuTUIEHMHY8Gnwcz\n 9rjkxyY6XlCVFO4fp6Mi69oXnd96LY24eyh/eyWlQ17yiaVf2kMSGLZW+x+rpGhYYDxa\n CdutjaPtAju5SdiglrHo7lC75Gm2wiMOULSZNHGQYxeR5TqUTpxG1yKy0F2tyQTvu1zO\n EjEsAeLpYvSSLkTO+M0LIHEf7tPrHRhUqhY4l/4CB3CAz3CST/ZepXKtKoq1SKObFUYu\n qf3ghcNylhi5fh8f8IXes41zjAr6jZVD1FJjxJoFjKDR6POjKrmf5/Wfpz9EAIwT3vn6\n HAhw==","X-Gm-Message-State":"AOJu0YwN7K+F96bha2QdQ21Nl/UY4GH0opDJ6CTPnumrE8lHxMOb4vfG\n +d+WeR+QstnYtFlY40TgPEBMIkm+TO85D1YaR9V98RBa339hj2ixlbu+Fza7Mg==","X-Gm-Gg":"AeBDiesVc2/6FfnDw8JeTjFSpOVVEVL0IdXK7GRQ8DlW2WYNHwc44gLmshWnKusGEg2\n 9yhIfPBrZn65Bqq5ZsMo9crQocTsOGE0u10WPNgooqNhAr9h8PR+qdIhbGSVo69tT9NZBTzOItD\n zG0PAkE6mLuxttEw3jUl7kuQLBRX1C3C3rtUzqNNDodAFjMrUe3pPX/LiLQmwBDDhSsI7IhZaXb\n CVYZ33ZGhiHbSNUL9VFey1zoMloh9sRGTG+NeRKi+sL3qNXcLMwx0R6O7gxYZ71HnFWdp++KQrA\n NfE4jnB1Vmr5v4qEhcEpWu/Bd2jef1Cvfn5n2BZ2pYVkPsucFmu5c5mT5FOs2n8WGdaqV5saAQ9\n oAdG+JaFE2egiyEVRpb6pwzBfLpLWDeWpoC52GgEC0F3z+GQPiXdtv/HpduX46zyqSPl/rXmA9d\n ulFSXFsATy9coy7hSkFf7+wWPM5vwvnGiT1gP+ljLJvNbc","X-Received":"by 2002:a17:902:d2c9:b0:2b2:42c0:de33 with SMTP id\n d9443c01a7336-2b281838874mr56076645ad.4.1775396053661;\n Sun, 05 Apr 2026 06:34:13 -0700 (PDT)","Date":"Sun, 5 Apr 2026 23:34:07 +1000","From":"Nathaniel Shead <nathanieloshead@gmail.com>","To":"gcc-patches@gcc.gnu.org","Cc":"Jason Merrill <jason@redhat.com>","Subject":"[PATCH] c++/modules: Only mark namespace-scope entities as exported\n [PR124781]","Message-ID":"<adJkz7LoEuf_78_o@Thaum.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?\n\n-- >8 --\n\nWe call 'set_originating_module' before we call pushdecl, which means\nthat for function-scope entities we might not have set DECL_CONTEXT yet.\nUsually this doesn't matter, we only look at DECL_MODULE_EXPORT/ATTACH_P\non namespace-scope entities to begin with, but in the case in the linked\nPR it causes issues because declarations in an unevaluated lambda appear\nto be in an internal context.\n\nFixed by only considering non-null DECL_CONTEXT as being namespace scope\nwithin set_originating_module.\n\nAs a drive-by improvement, ensured that we only talk about unnamed\nnamespaces in the diagnostic within check_module_decl_linkage if we're\nactually within an anonymous namespace; this should be equivalent but\nwill lead to a slightly clearer diagnostic if a similar bug crops up\nagain later.\n\n\tPR c++/124781\n\ngcc/cp/ChangeLog:\n\n\t* module.cc (set_originating_module): Add a function comment,\n\tonly set attachment/exporting for entities with non-NULL\n\tDECL_CONTEXT.\n\t(check_module_decl_linkage): Use decl_anon_ns_mem_p instead of\n\tdecl_internal_context_p.\n\ngcc/testsuite/ChangeLog:\n\n\t* g++.dg/modules/export-7.C: New test.\n\nSigned-off-by: Nathaniel Shead <nathanieloshead@gmail.com>\n---\n gcc/cp/module.cc                        | 10 ++++++++--\n gcc/testsuite/g++.dg/modules/export-7.C | 10 ++++++++++\n 2 files changed, 18 insertions(+), 2 deletions(-)\n create mode 100644 gcc/testsuite/g++.dg/modules/export-7.C","diff":"diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc\nindex 6958388e454..a8517569a1b 100644\n--- a/gcc/cp/module.cc\n+++ b/gcc/cp/module.cc\n@@ -22076,12 +22076,18 @@ set_defining_module_for_partial_spec (tree decl)\n     vec_safe_push (partial_specializations, decl);\n }\n \n+/* Record that DECL is declared in this TU, and note attachment and\n+   exporting for namespace-scope entities.  FRIEND_P is true if\n+   this is a friend declaration.  */\n+\n void\n set_originating_module (tree decl, bool friend_p ATTRIBUTE_UNUSED)\n {\n   set_instantiating_module (decl);\n \n-  if (!DECL_NAMESPACE_SCOPE_P (decl))\n+  /* DECL_CONTEXT may not be set yet when we're called for\n+     non-namespace-scope entities.  */\n+  if (!DECL_CONTEXT (decl) || !DECL_NAMESPACE_SCOPE_P (decl))\n     return;\n \n   gcc_checking_assert (friend_p || decl == get_originating_module_decl (decl));\n@@ -22134,7 +22140,7 @@ check_module_decl_linkage (tree decl)\n \t internal namespace as exporting a declaration with internal\n \t linkage, as this would also implicitly export the internal\n \t linkage namespace.  */\n-      if (decl_internal_context_p (decl))\n+      if (decl_anon_ns_mem_p (decl))\n \t{\n \t  error_at (DECL_SOURCE_LOCATION (decl),\n \t\t    \"exporting declaration %qD declared in unnamed namespace\",\ndiff --git a/gcc/testsuite/g++.dg/modules/export-7.C b/gcc/testsuite/g++.dg/modules/export-7.C\nnew file mode 100644\nindex 00000000000..11001390d17\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/modules/export-7.C\n@@ -0,0 +1,10 @@\n+// PR c++/124781\n+// { dg-do compile { target c++20 } }\n+// { dg-additional-options \"-fmodules\" }\n+// { dg-module-cmi foo }\n+\n+export module foo;\n+export using xx = decltype([] {\n+  using yy = int;\n+  int abc = 123;\n+}());\n","prefixes":[]}