Bug 22009 - Friend declaration of a private member function produces error in g++-4.0
Summary: Friend declaration of a private member function produces error in g++-4.0
Status: RESOLVED DUPLICATE of bug 7809
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-10 19:20 UTC by Fariborz Jahanian
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: apple-ppc-darwin
Target: apple-ppc-darwin
Build: apple-ppc-darwin
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fariborz Jahanian 2005-06-10 19:20:52 UTC
I think following test case is correct. But g++-4.0 produces a diagnostics. We should be able to declare 
a private member function of a class as a friend of another class in order for the member function be 
able to access private members of the befriended class. 

class FriendTestTo;

class FriendTestFrom
{
private:
        void reallySetIt (FriendTestTo* PF);
};

class FriendTestTo
{
private:
  int i;
  friend void FriendTestFrom::reallySetIt (FriendTestTo*);
};

void FriendTestFrom::reallySetIt (FriendTestTo* PF){ PF->i = 1; };
% g++ -c test.cc
test.cc:6: error: 'void FriendTestFrom::reallySetIt(FriendTestTo*)' is private
test.cc:13: error: within this context

Workaround is to declare class FriendTestFrom as friend of class FriendTestTo.
Comment 1 Andrew Pinski 2005-06-10 19:24:54 UTC
The code is invalid.

See DR 209 which was closed as not a defect.
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#209

This is a dup of bug 7809 which changed the behavior of GCC to match the standard.

*** This bug has been marked as a duplicate of 7809 ***