This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


501. Visibility of friend declarations within the befriending class

Section: 11.8.4  [class.friend]     Status: NAD     Submitter: Gabriel Dos Reis     Date: 25 Jan 2005

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.

Rationale (April, 2005):

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