]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
doc, c++: Document that anonymous namespaces have internal linkage [PR124773]
authorSandra Loosemore <sloosemore@baylibre.com>
Thu, 9 Apr 2026 23:43:35 +0000 (23:43 +0000)
committerSandra Loosemore <sloosemore@baylibre.com>
Thu, 9 Apr 2026 23:57:05 +0000 (23:57 +0000)
gcc/ChangeLog
PR c++/124773
* doc/trouble.texi (Linkage in Anonymous Namespaces): New section.

gcc/doc/trouble.texi

index ad13357c30a7540755cbde108c6aa2c121ea111a..4882e2fababc90fe0cbdace3339952c6c86b3585 100644 (file)
@@ -638,6 +638,7 @@ give rise to questions of this sort.
 * Name lookup::         Name lookup, templates, and accessing members of base classes
 * Temporaries::         Temporaries may vanish before you expect
 * Copy Assignment::     Copy Assignment operators copy virtual bases twice
+* Linkage in Anonymous Namespaces::  Names have internal linkage
 @end menu
 
 @node Static Definitions
@@ -912,6 +913,21 @@ copy-assignment operator removes any uncertainties.  With such an
 operator, the application can define whether and how the virtual base
 subobject is assigned.
 
+@node Linkage in Anonymous Namespaces
+@subsection Linkage in Anonymous Namespaces
+
+The C++11 standard changed the linkage of anonymous namespaces from
+external (using a unique generated name) to internal.  That means that
+names declared in such a namespace now also have internal linkage, and
+@code{extern "C"} has no effect.  GCC implemented this change in
+behavior starting with the GCC 15 release; code using this idiom that
+worked in earlier versions of GCC, or with @option{-std=} options
+prior to C++11, may encounter unexpected linker issues due to changes
+in name mangling.
+
+For more information about the change to the C++ standard, see
+@uref{https://cplusplus.github.io/CWG/issues/2772.html}.
+
 @node Non-bugs
 @section Certain Changes We Don't Want to Make