c++/3084: anonymous namespace linking
Artem Khodush
artem@duma.gov.ru
Fri Jun 8 06:18:00 GMT 2001
> anonymous namespace functions cannot be linked
> to global call to these functions.
>
> There is an error when linking an object file with
> the code of a function declared inside a unnamed
> "namespace {}".
>
> In the .o that includes the function code, the name
> is the form *__GLOBAL__* where in the .o that refers
> to the function code, the name is different.
>
This is not a bug, this behavior is requred by the c++
standard, and is the very reason of existence of
unnamed namespaces.
7.3.1.1 - Unnamed namespaces [namespace.unnamed]
-1- An unnamed-namespace-definition behaves as if it were
replaced by
namespace 'unique' { /* empty body */ }
using namespace 'unique';
namespace 'unique' { namespace-body }
where all occurrences of 'unique' in a translation unit are
replaced by the same identifier and this identifier differs
from all other identifiers in the entire program.*
[Footnote: Although entities in an unnamed namespace
might have external linkage, they are effectively qualified
by a name unique to their translation unit and therefore
can never be seen from any other translation unit.
--- end footnote]
More information about the Gcc-bugs
mailing list