Topic: For discussion: 11.4/7


Author: rlankine@hotmail.com ("Risto Lankinen")
Date: Mon, 8 Dec 2003 15:07:31 +0000 (UTC)
Raw View
Hi!

In 11.4/7 it says:

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

This has two - practically opposite - interpretations:

1. A name nominated by a friend declaration [will implicitly become]
accessible in the scope of the class containing the friend declaration.

2. A name nominated by a friend declaration [must explicitly have been
declared as] accessible in the scope of the class containing the friend
declaration.

The difference between the interpretations can be pointed out with the
following code:

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

class D
{
   friend void C::f();
};

This satisfies interpretation (1), but fails to satisfy interpretation (2).

Alas, if (1) is the correct interpretation, then the phrasing seemingly
also allows the following:

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

class D
{
   friend void C::f();

   D()
   {
      C::f();
   }
};

.... thereby granting a broader access to a private method than what
was probably intended.

(See also
http://groups.google.fi/groups?selm=rv%25zb.4235%24g4.94697%40news2.nokia.co
m )

So, which is the correct interpretation?

[Whichever it is, there seems to be a defect:  At least the phrasing
is ambiguous; additionally if (1) is the correct interpretation then the
phrasing is also overly permissive.]

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                       ]





Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 9 Dec 2003 06:40:51 +0000 (UTC)
Raw View
Risto Lankinen wrote:
> In 11.4/7 it says:
>
> "A name nominated by a friend declaration shall be accessible in the
> scope of the class containing the friend declaration."
>
> This has two - practically opposite - interpretations:
>
 > <snips>

I read your previous post about the same subject and came to the same
conclusion. The use of the word "shall" is unfortunate.

> So, which is the correct interpretation?

Clearly, it is number (2). Just consider 11.4/1:

"A member of a class can be:
- private; that is, its name can be used only by members and friends of
the class in which is is declared.
[...]"

This rules out interpretation (1) entirely, as otherwise any class could
get access to any private or protected member of any other class without
being declared friend by the latter. The whole thing about access
control would lose meaning completely, in this case.

> [Whichever it is, there seems to be a defect:  At least the phrasing
> is ambiguous; additionally if (1) is the correct interpretation then the
> phrasing is also overly permissive.]

Technically, it's not really a defect if we interpret the word "shall"
as in <http://www.ietf.org/rfc/rfc2119.txt>. Sure is that if we replaced
the word "shall" with "must" the sentence would not change meaning, any
trace of ambiguity would disappear and a lot of people (including
myself) would be much happier.

Just my two eurocents.

Alberto Barbati

---
[ 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                       ]