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

2024-11-11


2370. friend declarations of namespace-scope functions

Section: 6.5.3  [basic.lookup.unqual]     Status: CD6     Submitter: Andrew Marino     Date: 2017-12-04

[Accepted at the November, 2020 meeting as part of paper P1787R6 and moved to DR at the February, 2021 meeting.]

Issue 1906 discussed unqualified lookup in friend declarations of class member functions, and CWG decided to reaffirm the existing specification without change. However, there is a similar issue regarding friend declarations of namespace-scope functions. According to 6.5.3 [basic.lookup.unqual] paragraph 9,

Name lookup for a name used in the definition of a friend function (11.8.4 [class.friend]) defined inline in the class granting friendship shall proceed as described for lookup in member function definitions. If the friend function is not defined in the class granting friendship, name lookup in the friend function definition shall proceed as described for lookup in namespace member function definitions.

In particular, “as described for lookup in member function definitions” does not consider names declared in the namespace of the friend function, and non-defining friend declarations of namespace-scope functions are not described at all. There is implementation divergence on these points. For example:

  namespace N {
    typedef int type;
    void f(type);
    void g(type);
    void h(type);
  }
  class C {
    typedef N::type N_type;
    friend void N::f(type) { }  // Ill-formed: cannot define namespace friend
    friend void N::g(type);     // Unclear whether type is found or not
    friend void N::h(N_type);   // Unclear whether N_type is found or not
  };

Notes from the November, 2018 meeting:

CWG agreed that the lookup for functions in namespaces should be similar to that for class member functions.