Article View: gnu.g++.bug
Article #2109Error not produced correctly on incorrect access of private data.
From: fred
Date: Fri, 22 Dec 1989 03:34
Date: Fri, 22 Dec 1989 03:34
50 lines
1550 bytes
1550 bytes
The GNU C++ compiler appears to allow access to data which violates C++
protection rules. The following two examples will illustrate the problem.
These examples are taken from the Unix System V, AT&T C++ Language
System Release 2.0 Selected Readings Manual, Chapter 7.
class B
{
friend void f1();
public:
int a;
};
class C : private B
{
friend void f2();
};
class D : public C{};
void f1()
{
D* p1;
p1->a=1; // This should be an error.
}
Since f1 is referencing 'a' from a pointer to a D object which is
derived from a public C which is derived from a private B. This means
that B::a is a private member of the derived class C. Only friends and
members of C should have access to B::a in the derived class C.
class B
{
int i;
friend class D;
};
class C : private B {};
class D : public C
{
void f()
{
int fi1=i; // This should be an error.
}
};
Again B::i is a private member of class C. Only public and protected
members of the base class C are avaible to members and friends of the
derived class D.
Technical Details
Message-ID:
<8912220335.AA12109@saber.tera.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!SABER.TERA.COM!fredShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!SABER.TERA.COM!fred From: fred@SABER.TERA.COM Newsgroups: gnu.g++.bug Subject: Error not produced correctly on incorrect access of private data. Message-ID: <8912220335.AA12109@saber.tera.com> Date: 22 Dec 89 03:34:59 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 50