Thread View: gnu.g++.bug
1 messages
1 total messages
Started by fred
Fri, 22 Dec 1989 03:34
Error not produced correctly on incorrect access of private data.
Author: 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads