This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3084: anonymous namespace linking
- To: <conversy at emn dot fr>
- Subject: Re: c++/3084: anonymous namespace linking
- From: "Artem Khodush" <artem at duma dot gov dot ru>
- Date: Fri, 8 Jun 2001 16:48:55 +0400
- >Received: from artem by mailsrv.duma.gov.ru (SMI-8.6/SMI-SVR4)id QAA26709; Fri, 8 Jun 2001 16:51:52 +0400
- Cc: <gcc-gnats at gcc dot gnu dot org>, <gcc-bugs at gcc dot gnu dot org>
- References: <20010608114905.11866.qmail@sourceware.cygnus.com>
> 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]