This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]