[{"id":3673802,"web_url":"http://patchwork.ozlabs.org/comment/3673802/","msgid":"<e0c3ef9c-ca56-40ae-a5d6-087bc54d92a8@redhat.com>","list_archive_url":null,"date":"2026-04-06T16:43:27","subject":"Re: [PATCH] c++/modules: Only mark namespace-scope entities as\n exported [PR124781]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/5/26 9:34 AM, Nathaniel Shead wrote:\n> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?\n\nOK.\n\n> -- >8 --\n> \n> We call 'set_originating_module' before we call pushdecl, which means\n> that for function-scope entities we might not have set DECL_CONTEXT yet.\n> Usually this doesn't matter, we only look at DECL_MODULE_EXPORT/ATTACH_P\n> on namespace-scope entities to begin with, but in the case in the linked\n> PR it causes issues because declarations in an unevaluated lambda appear\n> to be in an internal context.\n> \n> Fixed by only considering non-null DECL_CONTEXT as being namespace scope\n> within set_originating_module.\n> \n> As a drive-by improvement, ensured that we only talk about unnamed\n> namespaces in the diagnostic within check_module_decl_linkage if we're\n> actually within an anonymous namespace; this should be equivalent but\n> will lead to a slightly clearer diagnostic if a similar bug crops up\n> again later.\n> \n> \tPR c++/124781\n> \n> gcc/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> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/modules/export-7.C: New test.\n> \n> Signed-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\n> \n> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc\n> index 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\",\n> diff --git a/gcc/testsuite/g++.dg/modules/export-7.C b/gcc/testsuite/g++.dg/modules/export-7.C\n> new file mode 100644\n> index 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> +}());","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 (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=FlTTG3jO;\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 (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=FlTTG3jO","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"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 4fqFXL21Tnz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 07 Apr 2026 02:44:02 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 4EE024BA2E20\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  6 Apr 2026 16:44:00 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 933844BA2E23\n for <gcc-patches@gcc.gnu.org>; Mon,  6 Apr 2026 16:43:32 +0000 (GMT)","from mail-qk1-f200.google.com (mail-qk1-f200.google.com\n [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-135-xKY6tDbEP06iUO9Z9hTjMw-1; Mon, 06 Apr 2026 12:43:30 -0400","by mail-qk1-f200.google.com with SMTP id\n af79cd13be357-8cb706313beso563878585a.3\n for <gcc-patches@gcc.gnu.org>; Mon, 06 Apr 2026 09:43:30 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8aa1c6d5856sm38932436d6.46.2026.04.06.09.43.27\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Mon, 06 Apr 2026 09:43:27 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 4EE024BA2E20","OpenDKIM Filter v2.11.0 sourceware.org 933844BA2E23"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 933844BA2E23","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 933844BA2E23","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775493812; cv=none;\n b=k2YGE2+IGDYEBiMEIS1ij5AUfEMlx7SfoUtVgX15gEFatVNh2V2GHBJL22AhFOmB/y+OXdafqRCzfnDVd31jSUaA5UwUYmdRvl1wHPSotp44+/HAEPHiZ8zRK1WpTRWIkO3AARxt/KZrp2CPQWJaeY3SpbGZNkUyqc5rPtqMk+U=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775493812; c=relaxed/simple;\n bh=/vig1m3if2EFoAw7e5J1RKxk+VrvwFVcr4Fukzlh37A=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=YOeIY6WQujhj5kAXWMNz1WxQA2rUy1OCiQl7XkofHSh2tW+bk/lqGM3i+fyBTDSlo3Wz+7ZhocMrtuSjtf4i67xTrkOfOoJKi3nrAprO0nFuRODGTB4q302E7rFWO2fZKotiRuGy+BgUD/Zcm5x/zMVwRshX/RMEw5wSQJuEubw=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775493812;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=rD2d6ABo+8+Oim4Fqep0f28FtXB3LRk3c2g6cr6a0sk=;\n b=FlTTG3jOXCew+xMEn9PaXRo6q/NYnwIWnR0bYQR5OrJJRfmWIIGELgOLHVRfbcWPJgiiyK\n FAoyW1pluWVkSoTz0tr/EpUiCuxr1pNtBiN7oS8fGnRRoTCBNDjjR6+NiU1l73pgnSQjUn\n 4gPSv5NAeE9YRNf5fO9HsI0C4vIAvTo=","X-MC-Unique":"xKY6tDbEP06iUO9Z9hTjMw-1","X-Mimecast-MFC-AGG-ID":"xKY6tDbEP06iUO9Z9hTjMw_1775493810","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775493809; x=1776098609;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=rD2d6ABo+8+Oim4Fqep0f28FtXB3LRk3c2g6cr6a0sk=;\n b=EQZYJMlTsGcEfeHP3nVctMAQFsqR040hAoH+5HQ1V+ewI4xWL2xYTeYehNUGTi77fL\n ZeyuUh5l5V4ikBYHzW9J9G4bhRi6UlFf29Unj0tekxG8bz8mjZSUFH4H0eGQczoVpFsx\n HAGF7fls849Uc2EL2k98FWzETVsr4hpfXK6GFgELNbWgfWbzk5PnVHG7CIW0Iwh2300L\n 1s+CPfFpXT2MFfm4Xxu7wic6vQq+1UOCHPNTw2HtFjJWQ9z3rs635ZjGPiASScTe8mVe\n 8HPhaagdVC6xTMkt/EVNvzp6yL/sP3wnWAUm+2TUYJNOfjP/an2FhHbGuHNupVeuW4Ey\n RINA==","X-Forwarded-Encrypted":"i=1;\n AJvYcCVmUFI12EZox2h1v1yk4NdL0JaAVjgly9aLAcr3hzbU4i2Xsco4+vAA1rErHGLMTY4+CB4+SrUcueW3HA==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YwRbSnkMH9rBS+P3SRnko+0llq432yjMPoFt9SDD66rum22FeFu\n pYanUQ8hdEwbqmkGOORK7BCh5cJCNhTK83wu9f2YhcUGAESlPTwIVujr1D4X42jmpe1A7fx5Z2c\n l1heAE6HjRf+xqi8/BD0T8mdrb5ieBr/NZ2iiEAOHMafdw/sVENuY0vjIAuZFu9WN+ghPLA==","X-Gm-Gg":"AeBDietWVK+GBiKvgbFlJ/J+FQQS/W9RIrjtXR+1wU67ICO1P8N8B9VN61AJfmfJmxB\n +ZIqOv34r6vJYHytQq74Ai/pUBhE8D1w87smLGlSjErdL66cR+3PWaGaEVrVhVPPBhZknk3RHNh\n Uf4bRUhH1xcLyIxmGj1kcSQGxE0PR7XAlMwttHeFcPbowXGLL5LKdXqIzooGISYfjt+5rAv6LLw\n HYsBhIVZ8n0yFZdQhvsXITQiLKB1E6x6WcAh1RZPR6rFJ2mAuxtYrkEnuA7RlqciUuz+Nh7CHWS\n t3ekATDfUsI7O2pXjmoUGE8oSKbjQeWB2JWJ1yeLsHlMsRQwvAjEmeDKmz545Ov75q1I16SWx6A\n PiS+aA7FyspZ7WgcWgLdXG0q1TDIzmwTxKKvNRHlhBFg8imI5Y6IYcavLRXBlChhe0WjmxcBa+y\n +y7jl3NVRLYshJUJlSvXJ+V5OaYyTH9Qk=","X-Received":["by 2002:a05:620a:4003:b0:8d6:bd01:a684 with SMTP id\n af79cd13be357-8d6bd01b434mr935438385a.7.1775493809181;\n Mon, 06 Apr 2026 09:43:29 -0700 (PDT)","by 2002:a05:620a:4003:b0:8d6:bd01:a684 with SMTP id\n af79cd13be357-8d6bd01b434mr935434185a.7.1775493808636;\n Mon, 06 Apr 2026 09:43:28 -0700 (PDT)"],"Message-ID":"<e0c3ef9c-ca56-40ae-a5d6-087bc54d92a8@redhat.com>","Date":"Mon, 6 Apr 2026 12:43:27 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++/modules: Only mark namespace-scope entities as\n exported [PR124781]","To":"Nathaniel Shead <nathanieloshead@gmail.com>, gcc-patches@gcc.gnu.org","References":"<adJkz7LoEuf_78_o@Thaum.localdomain>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<adJkz7LoEuf_78_o@Thaum.localdomain>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"19KfUoQotS4_GN05aSvvHo-tD3gVQzTkA0nLKoAs1A4_1775493810","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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"}}]