This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/3084: anonymous namespace linking


> 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]





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]