Topic: Defect report: 11.4/7


Author: Risto Lankinen <rlankine@hotmail.com>
Date: Fri, 5 Dec 2003 16:40:50 +0000 (UTC)
Raw View
[ Forwarded to the C++ committee. -sdc ]

Hi!

Thus says the section 11.4/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.

Cheers!

 - Risto -




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]