public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* accessing private filds in 3.3.x
@ 2004-02-17  8:08 john gladkih
  2004-02-20  2:31 ` Jim Wilson
  2004-02-20  2:50 ` Jim Wilson
  0 siblings, 2 replies; 3+ messages in thread
From: john gladkih @ 2004-02-17  8:08 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: accessing private filds in 3.3.x
  2004-02-17  8:08 accessing private filds in 3.3.x john gladkih
@ 2004-02-20  2:31 ` Jim Wilson
  2004-02-20  2:50 ` Jim Wilson
  1 sibling, 0 replies; 3+ messages in thread
From: Jim Wilson @ 2004-02-20  2:31 UTC (permalink / raw)
  To: john gladkih; +Cc: gcc-bugs

john gladkih wrote:
> I found one stupid problem after migrating to gcc 3.3 - it does allow to
> access private fields in classes. Please, look here:

I am not enough of a C++ expert to answer this.  However, I can suggest 
that you file a bug report into our bug database rather than send email 
to gcc-bugs.  Bugs filed into bugzilla get tracked, and it is more 
likely that you will get an answer.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: accessing private filds in 3.3.x
  2004-02-17  8:08 accessing private filds in 3.3.x john gladkih
  2004-02-20  2:31 ` Jim Wilson
@ 2004-02-20  2:50 ` Jim Wilson
  1 sibling, 0 replies; 3+ messages in thread
From: Jim Wilson @ 2004-02-20  2:50 UTC (permalink / raw)
  To: john gladkih; +Cc: gcc-bugs

john gladkih wrote:
> I found one stupid problem after migrating to gcc 3.3 - it does allow to
> access private fields in classes. Please, look here:

I forgot to do some trivial checking.  I reproduced the problem with 
3.3, but I got the expected result with 3.2 and pre-3.4.  Thus it 
appears that this problem has already been fixed in the development 
sources, and it will be fixed when gcc-3.4 comes out.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-02-20  2:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-17  8:08 accessing private filds in 3.3.x john gladkih
2004-02-20  2:31 ` Jim Wilson
2004-02-20  2:50 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).