Title
friend declarations of namespace-scope functions
Status
cd6
Section
6.5.3 [basic.lookup.unqual]
Submitter
Andrew Marino

Created on 2017-12-04.00:00:00 last changed 28 months ago

Messages

Date: 2018-11-15.00:00:00

Notes from the November, 2018 meeting:

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

Date: 2020-11-15.00:00:00

[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
  };
History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: drwp -> cd6
2021-02-24 00:00:00adminsetstatus: accepted -> drwp
2020-12-15 00:00:00adminsetmessages: + msg6338
2017-12-04 00:00:00admincreate