{"id":2223532,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223532/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260415140617.2347118-1-jason@redhat.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/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},"msgid":"<20260415140617.2347118-1-jason@redhat.com>","date":"2026-04-15T14:05:11","name":"[pushed] c++: mangling of extern \"C\" in anon ns [PR117133]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"34cc344ab0e51a501e553a219be8e1c3f6c2fb58","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/1.1/people/4337/?format=json","name":"Jason Merrill","email":"jason@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260415140617.2347118-1-jason@redhat.com/mbox/","series":[{"id":499993,"url":"http://patchwork.ozlabs.org/api/1.1/series/499993/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499993","date":"2026-04-15T14:05:11","name":"[pushed] c++: mangling of extern \"C\" in anon ns [PR117133]","version":1,"mbox":"http://patchwork.ozlabs.org/series/499993/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223532/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223532/checks/","tags":{},"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=el56Tg30;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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=el56Tg30","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 [38.145.34.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 4fwjd11fQZz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 00:06:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id DCA1E4BA23DE\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 14:06:57 +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 9934B4BA2E17\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 14:06:27 +0000 (GMT)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-XfIz67R8NoqCf83_ALmhOw-1; Wed,\n 15 Apr 2026 10:06:20 -0400","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id BF1581955DE2; Wed, 15 Apr 2026 14:06:19 +0000 (UTC)","from jason-thinkpadp1gen4i.rmtusma.csb (unknown [10.22.66.21])\n by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id CBC9619560B1; Wed, 15 Apr 2026 14:06:18 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org DCA1E4BA23DE","OpenDKIM Filter v2.11.0 sourceware.org 9934B4BA2E17"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 9934B4BA2E17","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 9934B4BA2E17","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776261987; cv=none;\n b=G++wnYNsU0fIPN8DvMYAL2AYL7zixtQZK3Yad+LYR6dHsXCZHiqTlrK8jLdpPbJ6PmdbKCOVfRm/I7BIRhyQJev0tVI+blT0zDRiXdFBA6Ct7j9CfdVq/m7ca9xD89ZXQuT9QrVuYDvaQ4G+qvcKRc+PXTgf9iqR3VPdAOLnL0k=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776261987; c=relaxed/simple;\n bh=PpzdLfS4OExr/BxMG8NNr5PbO0m+8VDmPIrkX9qYU0s=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=o39PgunMo/hG9421gVntJcYy3LUNsbEeoAdDTQZmwE/6uaKOMmCFABQVNGxA91JKhFJHRthz/VdC8Q0Y/ok4nzHrP1vhdJnNSApvyxy7CMKkP9CU77okDPvusjQdy/eIZ1EeJkqBE+ZzA2YcHgBEJE81xtH1cFY5r7h0CECjF3s=","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=1776261987;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=yCrFSyCJFQ2IhxPDfzBolVg0gYztWJ3aivK838N2+Go=;\n b=el56Tg301t1HTAWII6pRbOACV61TDgIddl5dCR8s/vMAaH7udSKg22iCWqC00vDNsmCyy1\n 5U6Dp3ZkP3sfFb4Cgq94VV8+7M0LaQap3Tdg8+yELQIKdsDqUybwC/MFYMRKPag3TFlL5g\n E+Ey8tTy4wFwRX81ossjYTbwoN9ELgw=","X-MC-Unique":"XfIz67R8NoqCf83_ALmhOw-1","X-Mimecast-MFC-AGG-ID":"XfIz67R8NoqCf83_ALmhOw_1776261980","From":"Jason Merrill <jason@redhat.com>","To":"gcc-patches@gcc.gnu.org","Cc":"Sandra Loosemore <sloosemore@baylibre.com>,\n Jonathan Wakely <jwakely@redhat.com>","Subject":"[pushed] c++: mangling of extern \"C\" in anon ns [PR117133]","Date":"Wed, 15 Apr 2026 10:05:11 -0400","Message-ID":"<20260415140617.2347118-1-jason@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"jS-_wKOImp2nRg09BLPGUuk6ACyWP6WIBwpqmEGSQLM_1776261980","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=\"US-ASCII\"; x-default=true","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":"Tested x86_64-pc-linux-gnu, applying to trunk.\n\n-- 8< --\n\nr15-3910 updated decl_linkage to return 'internal' for extern \"C\"\ndeclarations in an anonymous namespace, as specified by C++11. This\nunintentionally changed the result of unmangled_name_p for such variables,\nthough functions were unaffected.\n\nThe standard says that only variables with external linkage have language\nlinkage, but it doesn't say anything about name mangling for declarations\nwith internal linkage, so I think we might as well retain the old mangling\nbehavior.  And then we don't need to document the mangling change.\n\nI also notice that such variables still get global symbols, as\nconstrain_visibility still thinks that extern \"C\" takes priority, but let's\nsave fixing (and documenting) that for GCC 17.\n\n\tPR c++/117133\n\tPR c++/124768\n\tPR c++/124773\n\ngcc/cp/ChangeLog:\n\n\t* mangle.cc (unmangled_name_p): Don't mangle internal extern \"C\"\n\tvariables.\n\ngcc/ChangeLog:\n\n\t* doc/trouble.texi (Linkage in Anonymous Namespaces): Remove.\n\ngcc/testsuite/ChangeLog:\n\n\t* g++.dg/abi/mangle84.C: New test.\n---\n gcc/doc/trouble.texi                | 16 ----------------\n gcc/cp/mangle.cc                    |  8 ++++----\n gcc/testsuite/g++.dg/abi/mangle84.C |  5 +++++\n 3 files changed, 9 insertions(+), 20 deletions(-)\n create mode 100644 gcc/testsuite/g++.dg/abi/mangle84.C\n\n\nbase-commit: 3bf1ba4c723b8fd6274fb134890c83031d00d408","diff":"diff --git a/gcc/doc/trouble.texi b/gcc/doc/trouble.texi\nindex 4882e2fabab..ad13357c30a 100644\n--- a/gcc/doc/trouble.texi\n+++ b/gcc/doc/trouble.texi\n@@ -638,7 +638,6 @@ give rise to questions of this sort.\n * Name lookup::         Name lookup, templates, and accessing members of base classes\n * Temporaries::         Temporaries may vanish before you expect\n * Copy Assignment::     Copy Assignment operators copy virtual bases twice\n-* Linkage in Anonymous Namespaces::  Names have internal linkage\n @end menu\n \n @node Static Definitions\n@@ -913,21 +912,6 @@ copy-assignment operator removes any uncertainties.  With such an\n operator, the application can define whether and how the virtual base\n subobject is assigned.\n \n-@node Linkage in Anonymous Namespaces\n-@subsection Linkage in Anonymous Namespaces\n-\n-The C++11 standard changed the linkage of anonymous namespaces from\n-external (using a unique generated name) to internal.  That means that\n-names declared in such a namespace now also have internal linkage, and\n-@code{extern \"C\"} has no effect.  GCC implemented this change in\n-behavior starting with the GCC 15 release; code using this idiom that\n-worked in earlier versions of GCC, or with @option{-std=} options\n-prior to C++11, may encounter unexpected linker issues due to changes\n-in name mangling.\n-\n-For more information about the change to the C++ standard, see\n-@uref{https://cplusplus.github.io/CWG/issues/2772.html}.\n-\n @node Non-bugs\n @section Certain Changes We Don't Want to Make\n \ndiff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc\nindex a577e4e2a1c..6e6b16d389d 100644\n--- a/gcc/cp/mangle.cc\n+++ b/gcc/cp/mangle.cc\n@@ -768,14 +768,14 @@ unmangled_name_p (const tree decl)\n     }\n   else if (VAR_P (decl))\n     {\n+      /* extern \"C\" declarations aren't mangled.  */\n+      if (DECL_NAMESPACE_SCOPE_P (decl) && DECL_EXTERN_C_P (decl))\n+\treturn true;\n+\n       /* static variables are mangled.  */\n       if (!DECL_EXTERNAL_LINKAGE_P (decl))\n \treturn false;\n \n-      /* extern \"C\" declarations aren't mangled.  */\n-      if (DECL_EXTERN_C_P (decl))\n-\treturn true;\n-\n       /* Other variables at non-global scope are mangled.  */\n       if (CP_DECL_CONTEXT (decl) != global_namespace)\n \treturn false;\ndiff --git a/gcc/testsuite/g++.dg/abi/mangle84.C b/gcc/testsuite/g++.dg/abi/mangle84.C\nnew file mode 100644\nindex 00000000000..2116f1ab2cb\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/abi/mangle84.C\n@@ -0,0 +1,5 @@\n+// PR c++/124768\n+// { dg-final { scan-assembler \"two:\" } }\n+// { dg-final { scan-assembler-not \"_ZN12_GLOBAL__N_13twoE:\" } }\n+namespace { extern \"C\" { int two = 2; } }\n+int main() { return two; }\n","prefixes":["pushed"]}