c++/9122: qualified name forced to be used in non-public derived class
HouZhenyu
hou_zhenyu@hotmail.com
Sat Jan 4 02:53:00 GMT 2003
Dear Neil
Have to bother you again.
While I follow your instruction and read the standand text 11.2-1 to 11.2-4,
I try to compile the example in the note of 11.2-3:
// begin example
class B {
public:
int mi; // non static member
static int si; // static member
};
class D : private B {
};
class DD : public D {
void f();
};
void DD::f() {
// mi = 3; // error: mi is private in D
// si = 3; // error: si is private in D
B b; // !!!line 15
b.mi = 3; // okay (b.mi is different from this->mi)
b.si = 3; // okay (b.si is different from this->si)
B::si = 3; // okay
// B* bp1 = this; // error: B is a private base class
B* bp2 = (B*)this; // !!!line 20, okay with cast
bp2->mi = 3; // okay: access through a pointer to B.
}
// end example
g++ 3.2 report "'class B' is inaccessible " at line 15 and 20, where the
standard text says ok.
I use the stardand text which is the freely available draft version that BS
put it as 'slightly out-of-date'.
Is this example just the one of the differences from the real standard or
other revisions?
Best regards,
HouZhenyu
----- Original Message -----
From: "Neil Booth" <neil@daikokuya.co.uk>
To: "ZhenYu Hou" <hou_zhenyu@hotmail.com>
Cc: <neil@gcc.gnu.org>; <gcc-bugs@gcc.gnu.org>
Sent: Friday, January 03, 2003 4:46 PM
Subject: Re: c++/9122: qualified name forced to be used in non-public
derived class
> ZhenYu Hou wrote:-
>
> > Sorry to bother you.
>
> No problem.
>
> > But I still believe c++/9122 is a bug as the "p" in
> > class "C" is not an access to the base of "C", but a newly defined
pointer.
> > Please see below:
> >
> > class A {};
> > class B : A {
> > A* pp; // not full qualified, OK!
> > };
> > class C : public B {
> > public:
> > C(A*);// compiler : `class A' is inaccessible
> > void f(A*) {} compiler : `class A' is inaccessible
> > A* p; // compiler : `class A' is inaccessible
> > ::A* p2; // full qualified, OK!
> > };
> >
> > I compiled the code with gcc2.95.3, VC7, BC5.5.1, all passed. And I
looked
> > up the C++ standard but have not found anything that forbid the sample
code
> > to compile.
>
> That just shows you that many compilers can be wrong.
>
> > Another point is if "A" in the sample was replace by "::A", all passed,
it
> > seems strange.
>
> 11.2p1 and 11.2p4 imply that A is accessible from B, but not from C.
> Hence the results you observe.
>
> Name lookup always gives the base class A in either case according to
> 3.4.1p7.
>
> Neil.
>
More information about the Gcc-bugs
mailing list