Movatterモバイル変換


[0]ホーム

URL:


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

2025-12-20


1477. Definition of afriend outside its namespace

Section:_N4868_.9.8.2.3  [namespace.memdef]    Status:CD3    Submitter:John Spicer    Date:2012-03-09

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

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

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

Taken literally, that would mean the following example isill-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 ofN::f appears in global scoperather than in namespace scope.

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 thatnamespace. If afriend declaration in a non-local class firstdeclares a class or function95 the friend class or functionis a member of the innermost enclosing namespace.The name of thefriend is not found byThefriend declaration doesnot by itself make the name visible to unqualified lookup(6.5.3 [basic.lookup.unqual]) orby qualified lookup(6.5.5 [basic.lookup.qual]). [Note: The name of thefriend will be visible in its namespace ifuntil amatching declaration is providedin thatatnamespace scope (either before or after the class definition grantingfriendship).end note] If a friend functionis called...



[8]ページ先頭

©2009-2026 Movatter.jp