accessing private filds in 3.3.x
john gladkih
john@kak-sam.to
Tue Feb 17 08:08:00 GMT 2004
Hi,
I found one stupid problem after migrating to gcc 3.3 - it does allow to
access private fields in classes. Please, look here:
#define RESOURCE( N, T, I, C ) \
class __##N : public noncopyable_t { \
mutable T Value; \
public: \
\
T get() const { T t = Value; Value = I; return t; }; \
void free() { if( Value != I ) { C; Value = I; } }; \
T & operator() () const { return Value; }; \
\
__##N () : Value( I ) {}; \
~__##N () { free(); }; \
} N
struct noncopyable_t { // it does not matter
noncopyable_t() {}
noncopyable_t( const noncopyable_t& );
};
class c_t {
private:
RESOURCE( a_v, int*, 0, delete Value; );
};
int *foo() {
return c_t().a_v();
}
a_v field is private in class c_t but it is accesible. why?!
[~]> /usr/local/gnu/bin/g++-3.3.2 -v
Reading specs from /usr/local/gnu/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: ./configure --prefix=/usr/local/gnu --program-suffix=-3.3.2 --enable-shared --enable-threads --with-cpu=i686 --enable-version-specific-runtime-libs --enable-languages=c,c++,java
Thread model: posix
gcc version 3.3.2
gcc 3.2.x did not have this problem.
--
john, http://john.kak-sam.to
More information about the Gcc-bugs
mailing list