This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Question w.r.t. inside class defined struct for C++ language lawer.


Karel Gardas <kgardas@objectsecurity.com> writes:

> Hello,
> 
> I have one issue w.r.t. inside class defined struct with Sun's C++
> compiler. I have reported them a bug and they claim their compiler is ok.
> The problem is that the code is perfectly compilable by gcc3.4.0, icc8.0,
> como4.3.3 and so I would like to know who is right and who is wrong and if
> I should report gcc bug. The code looks like (simplified case):
> 
>        1
>        2 #include <string>
>        3
>        4 class Foo
>        5 {
>        6 private:
>        7         typedef std::string Identifier;
>        8         //struct Operation;
>        9         //friend struct Operation;
>       10         struct Operation
>       11         {
>       12                 Identifier name;
>       13         };
>       14 };
>       15
>       16
> 
> Sun's CC complain about line 12:
> "/tmp/kgardas/bug.cc", line 12: Error: Foo::Identifier is not accessible from Foo::Operation.
> 1 Error(s) detected.
> 
> Sun's engineer wrote me this:
> ``This is not a bug:
> According to the 1998 C++ standard.  Struct members do not have any
> special access to other members of their enclosing class.
> You must explicitly grant permission.''

However, unless they implement the WP resolution to issue 77 (see
    http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#77), it is
    not possible to delcare a nested class a friend of its containing
    class - making nested classes IMO useless.

> 
> and he added to the test-case lines 8 and 9 (uncommented).
> 
> So my question is: are all compilers right? i.e. gcc, icc, como compiling
> it and CC complaining about it? Or are gcc, icc, como right and Sun's CC
> is wrong and also engineer from support is wrong? Or even are gcc, icc,
> como wrong and Sun right? Should I report compilation of this wrong code
> as a bug to gcc's bugzilla?

None of the above. gcc, icc, and como all follow the WP resolution of
    issue 105, which defines nested classes as members, and grants
    them access to private members of the outer class (see
    http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#105).

Sun CC follows the 1998 standard as was written at that time. Nobody
    is 'wrong', but it could be argued that Sun CC is behind the
    times. 


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