This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [C++] PATCH to give the anonymous namespace a null DECL_NAME


Geoff Keating <geoffk@geoffk.org> writes:

[...]

| > | When we get IMA for C++, we will have multiple anonymous namespaces in
| > | the same program, and they can't all be NULL_TREE.  The name will make
| > | it easier to find all the places that need to be changed.
| > 
| > I don't understand this.  Currently (I mean without IMA) , you can
| > have as many unnamed namespaces as you want in a given translation
| > unit.
| 
| C++ says:
| 
| An unnamed-namespace-definition behaves as if it were replaced by
| namespace <b>unique</b> { /* empty body */ }
| using namespace <b>unique</b>;
| namespace <b>unique</b> { <i>namespace-body</i> }
| 
| where all occurrences of <b>unique</b> in a translation unit are
| replaced by the same identifier and this identifier differs from all
| other identifiers in the entire program.

Yes. But

  (1) My point is that you can have an unnamed namespace per named
      namespace, in a given translation unit and they all will be
      different, and therefore receive different unique names.  E.g. 

      namesapce A { namespace { int i; } }
      namespace B { namespace { int i; } }
      namespace { int i; }

      i, A::i and B::i will receive different names because they
      belong to different unnamed namespaces.

  (2)  The changes operated by Jason do not affect the real unique
       names assigned to those unnamed namespaces.  The changes only
       touches parts where the real name was not used in any useful
       way  (pretty-ptinting, ...) AND they are fine because they just
       make the code more readable, I would say more uniform. 

| Thus, currently all anonymous namespace declarations in a compilation
| behave as if they have the same name,

No. See above.

|  and so this is invalid:
| 
| namespace { int i; }
| namespace { double i; }

This is invalid, not because all unnamed namespaces are the same,
but because it is a redeclaration of the same with different meaning
in the same nameapace.  Contrast that with the example I gave above.

| However, with IMA you can have both of these declarations at once, so
| long as they're in different translation units. 

If they belong to different translation units, they will still have
different unique names.  Jason's patch did not change that. 

| It will be useful to
| be able to tell which anonymous namespace is being referred to.

Yes.  That is even required.  But Jason's patch did not change that.

-- Gaby


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