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]

RTTI and access control problem.


I'm having trouble with RTTI and access  control.  B is a friend of
the whole A heirarchy.  I therefore expect that B is allowed to
to cast to a private base of A3.   Is this abug?  egcs version 971031.
  


g++ -o test14 test14.cc; test14
cast failed

//test14.cc---------------------------------------------------
#include <iostream.h>

class A1 {
 public:
	virtual void foo() {friend class B;};
};

class A2 : public virtual A1 {friend class B;};

class A3 : public virtual A1, private A2 {friend class B;};

class B
{
 public:
	B(A1* a) : itsA(dynamic_cast<A2*>(a)) {};
	A2* itsA;
};

int main()
{
	A1* a=new A3;
	B b(a);
	
	if (b.itsA) cout << "cast ok" << endl; else cout << "cast failed" <<
endl;
	return 0;
}
//---------------------------------------------------------------------


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