Title
Visibility of friend declarations within the befriending class
Status
nad
Section
11.8.4 [class.friend]
Submitter
Gabriel Dos Reis

Created on 2005-01-25.00:00:00 last changed 238 months ago

Messages

Date: 2005-04-15.00:00:00

Rationale (April, 2005):

The Standard is clear and consistent; this rule is the result of an explicit decision by the Committee.

Date: 2022-11-20.07:54:16

I just received a query from a user of why line #1 in the following snippet is ill-formed:

    void g(int (*)(int));

    template<class T>
    class A {
       friend int f(int) { return 0; }

       void h() {
           g(f);          // #1
       }
    };

I believe that the special invisibility rule about friends is too complicated and makes life too complicated, especially considering that friends in templates are not templates, nor can they be conveniently rewritten with a “first declare at the namespace scope” rule. I can understand the rules when they make programming easier or prevent some obvious “silly” mistakes; but that does not seem to be the case here.

John Spicer: See two papers that discuss this issue: N0878 by Bill Gibbons, which ultimately gave rise to our current rules, and N0913 by me as an alternative to N0878.

History
Date User Action Args
2005-05-01 00:00:00adminsetmessages: + msg1199
2005-05-01 00:00:00adminsetstatus: open -> nad
2005-01-25 00:00:00admincreate