Topic: ARM Specs Contradiction


Author: arthur@solomon.technet.sg (Arthur Sombrito)
Date: 8 Oct 92 12:36:35 GMT
Raw View

--

There seems to be a contradiction in ARM specifications regarding
friend function declarations. In p. 250, it is stated that A:"If a
class or a function mentioned as a friend has not been declared
its name is entered in the same scope as the name of the class
containing the friend declaration. In p. 251, it is stated that
B:"A function first declared in a friend declaration is equivalent
to an extern declaration." Which is the correct spec: a friend
function is entered in the same scope or it is entered in file scope?
Given the ff. example w/c is similar to the one in p. 188:

    class B {
      class C {
        friend f();
      };
    };

Following spec A, it would have created a B::f() member function.
I would therefore assume that  spec A is applicable only to classes.
Following that assumption, it would also mean that the usual scope
resolution rules are not followed for friend functions. For example:

    f();
    class A { f(); };
    class B {
      f();
      class C : public A {
        friend f();
      };
    };

Under normal scoping rules, the sequence would have been A::f(), B::f()
and ::f(). But in this circumstances, ::f() would always be the only
function visible to the friend declaration. A::f() and B::f() could only
be made friends by adding the class qualifiers.

Comments would be greatly appreciated.




Author: ark@alice.att.com (Andrew Koenig)
Date: 9 Oct 92 13:46:32 GMT
Raw View
In article <1992Oct8.123635.10160@nuscc.nus.sg> arthur@solomon.technet.sg (Arthur Sombrito) writes:

> Which is the correct spec: a friend
> function is entered in the same scope or it is entered in file scope?

At their meeting this summer, the ISO/ANSI committee decided that friend
functions should be entered in the nearest enclosing non-class scope.
That means that

 class A {
  class B {
   friend void f();
  };
 };

implicitly declares f at file scope.
--
    --Andrew Koenig
      ark@europa.att.com