Bug, forward friend declaration
Nathan Sidwell
nathan@acm.org
Mon Feb 8 06:48:00 GMT 1999
Hi,
It appears egcs does not permit you to declare a member function of an
incomplete class to be a friend. This means you cannot define two classes with
mutually friendly member functions -- unless you make the classes friends. I
attach a test case, suitable for insertion into the test suite.
with the 19990131 snapshot, I get,
nathan@manao:549>uname -a && ss-g++ -v
SunOS manao 5.6 Generic_105181-03 sun4u sparc SUNW,Ultra-5_10
Reading specs from
/local/nathan/ss/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.93.04/specs
gcc version egcs-2.93.04 19990131 (gcc2 ss-980929 experimental)
nathan@manao:550>ss-g++ friend
friend.ii friend6.C
nathan@manao:550>ss-g++ friend6.C -c
friend6.C:12: member `B::fn()' declared as friend before type `B' defined
The CD2 11.4 (class.friend) para 4 talks about making X::foo a friend of Y. It
does not mention whether X has to be declared at that point.
I believe the diagnostic to be incorrect, if I am wrong, could someone point me
to the relevant part of the standard?
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
// Build don't link:
// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 8 Feb 1999 <nathan@acm.org>
// Check mutual friendship
class A;
class B;
class A
{
friend void B::fn();
public:
void A::fn();
};
class B
{
friend void A::fn();
public:
void B::fn();
};
More information about the Gcc-bugs
mailing list