Title
Wording issue on friend declarations
Status
nad
Section
11.8.4 [class.friend]
Submitter
Risto Lankinen

Created on 2003-12-05.00:00:00 last changed 252 months ago

Messages

Date: 2004-03-15.00:00:00

Notes from the March 2004 meeting:

We considered this and concluded that the standard is clear enough.

Date: 2003-12-05.00:00:00

Thus says the section 11.8.4 [class.friend]/7 in ISO 14882 C++ standard:

A name nominated by a friend declaration shall be accessible in the scope of the class containing the friend declaration.

The obvious intention of this is to allow a friend declaration to specify a function (or nested class, enum, etc.) that is declared "private" or "protected" in its enclosing class. However, literal interpretation seems to allow a broader access to the befriended function by the whole class that is declaring the friendship.

If the rule were interpreted literally as it is currently written, this would compile (when it, of course, shouldn't be allowed at all):

class C
{
private:
  static void f();
};

class D
{
  friend void C::f();  // A name nominated by friend declaration...

  D()
  {
   C::f();  // ... shall be accessible in scope of class declaring friendship
  }
};

Suggested fix is to reword "in the scope of the class containing the friend declaration" to exclude all other references from the scope of the declaring class, except the friend-declaration itself.

History
Date User Action Args
2004-04-09 00:00:00adminsetmessages: + msg1034
2004-04-09 00:00:00adminsetstatus: open -> nad
2003-12-05 00:00:00admincreate