public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Nested Class Member Access
@ 2004-09-03 15:35 Steven L. Zook
  2004-09-03 18:26 ` Giovanni Bajo
  0 siblings, 1 reply; 5+ messages in thread
From: Steven L. Zook @ 2004-09-03 15:35 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GCC Mailing List (E-mail)

Is this behavior on GCC's part (that is, nested classes are members of the enclosing class and thus have all access rights that other members have) intentional? 

If so, should it be documented in the "Extensions to the C++ Language" section of the GCC online documents.

In any case, it seems that I should not submit a problem report.

-----Original Message-----
From: Florian Weimer [mailto:fw@deneb.enyo.de]
Sent: Thursday, September 02, 2004 12:23 PM
To: Steven L. Zook
Cc: GCC Mailing List (E-mail)
Subject: Re: Nested Class Member Access


* Steven L. Zook:

> According to ISO/IEC 14882-2003 (is this the correct standard for
> GCC?) 11.8.1 [class.access.nest], I believe this should be an
> error. The paragraph says that nested classes have no special access
> rights to enclosing class members. Since cOuter::Variable is
> private, cOuter::cInner::Function should not have access to it.

Your are correct that your example is not valid C++, but this may
change:

  <http://ra.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45>

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

* Re: Nested Class Member Access
  2004-09-03 15:35 Nested Class Member Access Steven L. Zook
@ 2004-09-03 18:26 ` Giovanni Bajo
  2004-09-03 21:15   ` Joe Buck
  0 siblings, 1 reply; 5+ messages in thread
From: Giovanni Bajo @ 2004-09-03 18:26 UTC (permalink / raw)
  To: Steven L. Zook; +Cc: gcc

Steven L. Zook wrote:

> Is this behavior on GCC's part (that is, nested classes are members of the
> enclosing class and thus have all access rights that other members have)
> intentional?

Yes.

> If so, should it be documented in the "Extensions to the C++ Language"
> section of the GCC online documents.

Not really, because it is actually part of C++0x, so it is not a real
extension in the traditional term. Instead, I would like to define a new
language dialect (-std=c++0x) to activate such behavours (that is,
implementation of DRs which are in WP status). There have been some talk
about it, but no patches yet.

Giovanni Bajo

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

* Re: Nested Class Member Access
  2004-09-03 18:26 ` Giovanni Bajo
@ 2004-09-03 21:15   ` Joe Buck
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Buck @ 2004-09-03 21:15 UTC (permalink / raw)
  To: Giovanni Bajo; +Cc: Steven L. Zook, gcc

On Fri, Sep 03, 2004 at 08:26:26PM +0200, Giovanni Bajo wrote:
> Steven L. Zook wrote:
> 
> > Is this behavior on GCC's part (that is, nested classes are members of the
> > enclosing class and thus have all access rights that other members have)
> > intentional?
> 
> Yes.
> 
> > If so, should it be documented in the "Extensions to the C++ Language"
> > section of the GCC online documents.
> 
> Not really, because it is actually part of C++0x, so it is not a real
> extension in the traditional term. Instead, I would like to define a new
> language dialect (-std=c++0x) to activate such behavours (that is,
> implementation of DRs which are in WP status). There have been some talk
> about it, but no patches yet.

Speaking of c++0x, I'd dearly like to see an implementation of the "auto"
proposal that Stroustrup has championed, so loops iterating over
containers can be written simply and uniformly as

    for (auto iter = container.begin(); iter != container.end(); ++iter) {
	...;
    }    

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

* Re: Nested Class Member Access
  2004-09-02 19:13 Steven L. Zook
@ 2004-09-02 19:22 ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2004-09-02 19:22 UTC (permalink / raw)
  To: Steven L. Zook; +Cc: GCC Mailing List (E-mail)

* Steven L. Zook:

> According to ISO/IEC 14882-2003 (is this the correct standard for
> GCC?) 11.8.1 [class.access.nest], I believe this should be an
> error. The paragraph says that nested classes have no special access
> rights to enclosing class members. Since cOuter::Variable is
> private, cOuter::cInner::Function should not have access to it.

Your are correct that your example is not valid C++, but this may
change:

  <http://ra.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45>

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

* Nested Class Member Access
@ 2004-09-02 19:13 Steven L. Zook
  2004-09-02 19:22 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Steven L. Zook @ 2004-09-02 19:13 UTC (permalink / raw)
  To: GCC Mailing List (E-mail)

I'm using gcc 3.4.1 (I've also tried it with 3.3.1) m68k-elf and the following test file:



class cOuter { private: int Variable;
               public:  class cInner { public: int Function( cOuter * pOuter ); };
             };
int cOuter::cInner::Function( cOuter * pOuter ) { return pOuter->Variable; }



This fragment compiles without complaint, the produced code looks good. 

According to ISO/IEC 14882-2003 (is this the correct standard for GCC?) 11.8.1 [class.access.nest], I believe this should be an error. The paragraph says that nested classes have no special access rights to enclosing class members. Since cOuter::Variable is private, cOuter::cInner::Function should not have access to it.

I've searched bugzilla and found a couple of bugs posted against java for similar cases as well as #13495 (which may be related but whose example is rather obfuscated by templates).

Any C++ language lawyer comment would be appreciated. I will post a bug report if any GCC legal staff ;-) agrees that this is in violation.

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

end of thread, other threads:[~2004-09-03 21:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-03 15:35 Nested Class Member Access Steven L. Zook
2004-09-03 18:26 ` Giovanni Bajo
2004-09-03 21:15   ` Joe Buck
  -- strict thread matches above, loose matches on Subject: below --
2004-09-02 19:13 Steven L. Zook
2004-09-02 19:22 ` Florian Weimer

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).