egcs g++ 2.91.09 CVS snapshot, Allows access to private class members

ak@muc.de ak@muc.de
Thu Mar 12 00:04:00 GMT 1998


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









More information about the Gcc-bugs mailing list