c++/359: g++ incorrectly grants access to private members to nested classes

panisset@discreet.com panisset@discreet.com
Wed Jun 28 18:16:00 GMT 2000


>Number:         359
>Category:       c++
>Synopsis:       g++ incorrectly grants access to private members to nested classes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 28 18:16:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     panisset@discreet.com
>Release:        2.96 20000625
>Organization:
>Environment:

>Description:
g++ incorrectly grants access to private types in nested
classes/structs. According to ANSI/ISO C++ 11.8.1:

"The members of a nested class have no special access to
members of an enclosing class...".

The following test program demonstrates this problem:
// This test program demonstrates the gcc 2.96 incorrectly grants
// access to private members to nested classes, which should have
// no special access, according to ANSI/ISO C++ 11.8.1

class foo {
private:
  class bar {};
  struct baz {
     bar b;
  };
};

The SunPRO C++ 5.1 compiler gets this right:

"nested.C", line 9: Error: foo::bar is not accessible from foo::baz.
1 Error(s) detected.

>How-To-Repeat:
g++ -c nested.C

should generate an error, it does not.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-prs mailing list