This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
egcs g++ 2.91.09 CVS snapshot, Allows access to private class members
- To: egcs-bugs at cygnus dot com
- Subject: egcs g++ 2.91.09 CVS snapshot, Allows access to private class members
- From: ak at muc dot de
- Date: Thu, 12 Mar 1998 09:03:36 +0100
Hello,
This small program shows a bug in the egcs snapshot as of Mar. 1 (2.91.09,
current, not the release branch). Bla::Init is private, but g++ still
allows access to it to define an instance in an anonymous namespace.
Both Kai C++ and Tendra C++ correctly diagnose this as an error. The example
is more or less lifted from Stroustrup "The C++ Programming Language", p. 640
with some identifiers changed.
#include <iostream.h>
class Bla {
class Init;
};
class Bla::Init {
static int cnt;
public:
Init();
~Init();
};
namespace {
Bla::Init init; /* BUG! Init is private */
}
int Bla::Init::cnt = 0;
Bla::Init::Init()
{
if (++cnt == 0) cout << "Init" << endl;
}
Bla::Init::~Init()
{
if (--cnt == 0) cout << "Ende" << endl;
}
-Andi