This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Anonymous Namespaces
- From: Chris Lattner <sabre at nondot dot org>
- To: gcc at gcc dot gnu dot org
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>,Kevin Atkinson <kevina at gnu dot org>,Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Sat, 31 Jan 2004 13:00:09 -0600 (CST)
- Subject: Re: Anonymous Namespaces
Gabriel Dos Reis wrote:
> | > Yes because that is not the way C++ works, anonymous namespaces only
> | > give an unique name for that translation unit and that is it; it does
> | > not change the linkage of the symbol at all.
> |
> | Is there any harm is doing so?
> Yes. The second phase of two-phase name lookup ignores functions with
> internal linkages. Also, entities with internal linkage cannot be
> used as template arguments.
With the LLVM G++ front-end, all entities declared in an anonymous
namespace are emitted with internal linkage, including any related RTTI
info, vtables, etc.
This has absolutely no effect on the front-end, we handle it in our
version of "expand".
If you want, you can play with this in the LLVM demo page:
http://llvm.cs.uiuc.edu/demo
but make sure that you reference things in the anonymous namespace or they
will be deleted entirely, eg:
namespace {
int X;
}
void *Ref = &X; // Do not DCE X.
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/