This is the mail archive of the
mailing list for the GCC project.
Re: Static linkage and anonymous namespace
>>>>> Mark Mitchell <firstname.lastname@example.org> writes:
>>>>> "Martin" == Martin von Loewis <email@example.com> writes:
Martin> Under the as-if rule, a conforming C++ compiler can avoid
Martin> making members of anonymous namespaces accessible to other
Martin> translation units. For g++, the unique name of the
Martin> anonymous namespace is not entirely unique, so making
Martin> those identifiers .local improves conformance.
> I'm all for the end-result of this idea.
> But why can't we just make the definitions have internal linkage if
> they're in an anonymous namespace? Why do we need to introduce the
> TREE_PRIVATE bit? In other words, at some point the compiler decides
> whether to make things have internal or external linkage. Why doesn't
> it just use the DECL_CONTEXT (recursively looking at parent contexts)
> to see what linkage the thing should get?
1) From this standpoint, it would also make sense to make functions that
use types from an anonymous namespace internal; from Martin's
description, it sounds like his patch would do that (though I haven't
read it over). However,
2) The whole point of the anonymous namespace is to allow file-local
things to be used in situations where a name with external linkage is
required; for example, in template arguments.
So I don't think the patch is a good idea.