Topic: Req Clarification: private type used in parameter list of friend


Author: jhs@edg.com ("John H. Spicer")
Date: Fri, 17 Jan 2003 03:58:08 +0000 (UTC)
Raw View
Francis Glassborow wrote:
> In article <3e25d9b0$1_1@corp.newsgroups.com>, Alberto Barbati
> <abarbati@iaanus.com> writes
>
>>> The standard disallows a private type from being used in the
>>> base-clause of
>>> a friend class (11.4:2). A similar situation occurs in the use of a
>>> private
>>> type in the parameter list of a friend function -- a case on which the
>>> standard is silent. For example:
>>>  class X {
>>>     class B { };
>>>     friend void F (B b);
>>> };
>>>  void F(X::B b) // use of X::B ok here??
>>> {
>>> }
>>>  The above compiles with gcc, but not with Visual Studio.NET. Any
>>> ideas which
>>> is correct?
>>
>>
>> It seems to me that VS.NET is right. The standard is not silent about
>> this case, which is described in clause 7 of 11.4:
>>
>> "A name nominated by a friend declaration shall be accessible in the
>> scope of the class containing the friend declaration. [...]"
>>
>> as B is declared private, it's not accessible in the scope of class X.
>
>
> If that were true, it could not be used anywhere. However the reason
> VS.NET is right is rather simpler; the parameters of a function are not
> in the scope of the function because the arguments must be evaluated in
> the scope of the call, and that scope cannot access private members of X.
>
> A use of X::B in the body of a friend function would be fine.
>

VS.NET is wrong.  The declaration of f(X::B) is well-formed and should be
accepted.  This is described in the standard in clause 11 paragraph 5.

John Spicer
Edison Design Group

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: abarbati@iaanus.com (Alberto Barbati)
Date: Thu, 16 Jan 2003 04:36:20 +0000 (UTC)
Raw View
Lloyd J. Lewins wrote:
> The standard disallows a private type from being used in the base-clause of
> a friend class (11.4:2). A similar situation occurs in the use of a private
> type in the parameter list of a friend function -- a case on which the
> standard is silent. For example:
>
> class X {
>     class B { };
>     friend void F (B b);
> };
>
> void F(X::B b) // use of X::B ok here??
> {
> }
>
> The above compiles with gcc, but not with Visual Studio.NET. Any ideas which
> is correct?

It seems to me that VS.NET is right. The standard is not silent about
this case, which is described in clause 7 of 11.4:

"A name nominated by a friend declaration shall be accessible in the
scope of the class containing the friend declaration. [...]"

as B is declared private, it's not accessible in the scope of class X.

Alberto Barbati



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]