Title
Definition of a friend outside its namespace
Status
cd3
Section
_N4868_.9.8.2.3 [namespace.memdef]
Submitter
John Spicer

Created on 2012-03-09.00:00:00 last changed 130 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR at the April, 2013 meeting.]

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012):

Change _N4868_.9.8.2.3 [namespace.memdef] paragraph 3 as follows:

Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class or function95 the friend class or function is a member of the innermost enclosing namespace. The name of the friend is not found by The friend declaration does not by itself make the name visible to unqualified lookup (6.5.3 [basic.lookup.unqual]) or by qualified lookup (6.5.5 [basic.lookup.qual]). [Note: The name of the friend will be visible in its namespace if until a matching declaration is provided in that at namespace scope (either before or after the class definition granting friendship). end note] If a friend function is called...
Date: 2021-02-24.00:00:00

According to _N4868_.9.8.2.3 [namespace.memdef] paragraph 3,

Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class or function95 the friend class or function is a member of the innermost enclosing namespace. The name of the friend is not found by unqualified lookup (6.5.3 [basic.lookup.unqual]) or by qualified lookup (6.5.5 [basic.lookup.qual]) until a matching declaration is provided in that namespace scope (either before or after the class definition granting friendship).

Taken literally, that would mean the following example is ill-formed:

  namespace N {
    struct A {
      friend int f();
    };
  }
  int N::f() { return 0; }
  int i = N::f();    // ill-formed: N::f not found

because the definition of N::f appears in global scope rather than in namespace scope.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetmessages: + msg4403
2013-05-03 00:00:00adminsetstatus: tentatively ready -> dr
2012-11-03 00:00:00adminsetmessages: + msg4073
2012-11-03 00:00:00adminsetstatus: open -> tentatively ready
2012-03-09 00:00:00admincreate