Topic: A suspect bug in Visual C++ (a different one!)


Author: Francesco Potorti` <F.Potorti@cnuce.cnr.it>
Date: 1998/12/03
Raw View
"John E. Potter" <jpotter@falcon.lhup.edu> writes:

   class A {
     class B {
       struct C {};
       friend void f();
     };
     friend void f();
   };

   void f() {
     A::B::C *p;
     A::B *p2;
   }
   --> error C2248: 'C' : cannot access private struct declared in class 'A::B'

   You report the error on p from VC++.  I don't have it to check p2.

I just tried.  p2 does not generate an error.

   It is clearly not an error for either, VC++ wrong.

If I put "typedef int C" instead of "struct C {}" I get:
--> error C2248: 'C' : cannot access private typedef declared in class 'A::B'

So the error in VC++ does not seem to be tied to "struct".  Do you know if
it is worth reporting this as a bug?  To whom?

   Your original post without the second friend of A was good enough.

Sorry, I fear my English does not support me here.  What do you mean?

Thanks to you and to all that took the time to answer in this thread.

F.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francesco Potorti` <F.Potorti@cnuce.cnr.it>
Date: 1998/12/03
Raw View
Jason Merrill <jason@cygnus.com> writes:

   Yep.  g++ currently doesn't enforce access control on nested types.

Do you mean this is a known bug and it is not worth reporting?



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jason Merrill <jason@cygnus.com>
Date: 1998/12/02
Raw View
>>>>> John E Potter <jpotter@falcon.lhup.edu> writes:

 > You reported that egcs accepted the code.  I removed both of the
 > friend declarations and egcs still accepted it.  This is obviously
 > wrong and looks like the ARM rules.

Yep.  g++ currently doesn't enforce access control on nested types.

Jason


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "John E. Potter" <jpotter@falcon.lhup.edu>
Date: 1998/12/01
Raw View


On 30 Nov 1998, Francesco Potorti` wrote:

> The fact is, the example I posted was missing a line, so the real problem I
> was speaking about is another one.  The code I was asking opinions about is
> the following  one, which has  both friend declarations, but  generates the
> same error in VC++:
>
> -----------------------
> class A {
>   class B {
>     struct C {};
>     friend void f();
>   };
>   friend void f();
> };
>
> void f() {
>   A::B::C *p;

    A::B *p2;  // Let's add to the confusion

> }

You report the error on p from VC++.  I don't have it to check p2.
It is clearly not an error for either, VC++ wrong.

You reported that egcs accepted the code.  I removed both of the
friend declarations and egcs still accepted it.  This is obviously
wrong and looks like the ARM rules.

xlC seems to get these things right; so, I tried it.  With no friend
declarations, it rejects both p and p2, sounds good.  With only the
second friend of A, it rejects p and accepts p2, sounds good.  With
only the first friend of B, it accepts both.  I guess, A::B is visible
and since f is a friend of A::B, it can use it.

Your original post without the second friend of A was good enough.

John



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francesco Potorti` <F.Potorti@cnuce.cnr.it>
Date: 1998/11/30
Raw View
Francis Glassborow <francis@robinton.demon.co.uk> writes:

   I think you have to declare friend void f() in both A and B.  Can anyone
   quote the Standard to justify accepting the code as written?

To be true, I tend to agree with you (yet I'm not positive at all).

The fact is, the example I posted was missing a line, so the real problem I
was speaking about is another one.  The code I was asking opinions about is
the following  one, which has  both friend declarations, but  generates the
same error in VC++:

-----------------------
class A {
  class B {
    struct C {};
    friend void f();
  };
  friend void f();
};

void f() {
  A::B::C *p;
}
----------------------

baco2_VC.cpp(10) : error C2248: 'C' :
   cannot access private struct declared in class 'A::B'



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]