This is the mail archive of the gcc@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: Ambiguous base class


Again, here is my example:
   struct A { int x; };
   struct B1 : public A { };
   struct B2 : public A { };
   struct D : public B1, public B2 { };

   int f(D d) {
     return d.B1::A::x;
   }
I looked at this in the standard recently (in connection with the new
parser) -- but I don't remember what I read.

What I do remember is that you're supposed to look at "B1::A::x" as
two pieces: a nested-name-specifier (B1::A::) and an unqualified name.
You resolve the nested-name-specifier to a class or namespace; in this
case "A".  You then look for "x" in "A", and you can use "A" to
disambiguate things, but "B1" is lost to you at this point.

In other words, your case is no different than if you add in:

 struct Z { typedef A ZA; };

 return d.ZA::x;

Now, I do wish I remembered what lead me to this conclusion...

(FYI, EDG 3.0 rejects your test case as well.)

--
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com


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