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


Author: francis.glassborow@ntlworld.com (Francis Glassborow)
Date: Fri, 17 Jan 2003 17:04:33 +0000 (UTC)
Raw View
In article <3E27637D.3090706@edg.com>, John H. Spicer <jhs@edg.com>
writes
>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.

Thanks for the correction. I was forgetting that the  X::B whilst
superficially a pass by value (requiring copying) this can be met by
copying a temporary.


--
ACCU Spring Conference 2003 April 2-5
The Conference you cannot afford to miss
Check the details: http://www.accuconference.co.uk/
Francis Glassborow      ACCU

---
[ 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: llewins@west.raytheon.com ("Lloyd J. Lewins")
Date: Thu, 16 Jan 2003 20:29:43 +0000 (UTC)
Raw View
"Alberto Barbati" <abarbati@iaanus.com> wrote in message
news:3e25d9b0$1_1@corp.newsgroups.com...
> 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. [...]"
>
I think you have misinterpreted clause 7. My reading is that it allows
member functions of class X to call the friend function F, even if no other
declaration of X exists.

> as B is declared private, it's not accessible in the scope of class X.
>
I think this is clearly wrong. B being a member of X is clearly accessible
within X.

> Alberto Barbati
Lloyd Lewins

---
[ 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: francis.glassborow@ntlworld.com (Francis Glassborow)
Date: Fri, 17 Jan 2003 00:24:01 +0000 (UTC)
Raw View
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.




--
ACCU Spring Conference 2003 April 2-5
The Conference you cannot afford to miss
Check the details: http://www.accuconference.co.uk/
Francis Glassborow      ACCU

---
[ 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: llewins@west.raytheon.com ("Lloyd J. Lewins")
Date: Tue, 14 Jan 2003 03:14:53 +0000 (UTC)
Raw View
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?

Lloyd Lewins
Raytheon Co.

---
[ 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                       ]