Topic: It's a bug, right?


Author: clamage@taumet.Eng.Sun.COM (Steve Clamage)
Date: 19 Jun 1994 22:13:08 GMT
Raw View
In article 94Jun17124502@fnord.lehman.com, rfb@lehman.com (Rick Busdiecker) writes:
>Do friend functions have access to the same entities that member
>functions have?  In particular, do they have access to static member
>function that are inherited?

Yes, and yes. It's a compiler bug if a friend function can't access
protected members of a publicly-derived class.

---
Steve Clamage, stephen.clamage@eng.sun.com





Author: bkline%occs.nlm.nih.gov (Bob Kline)
Date: Thu, 23 Jun 94 01:22:04 GMT
Raw View
Steve Clamage (clamage@taumet.Eng.Sun.COM) wrote:
: In article 94Jun17124502@fnord.lehman.com, rfb@lehman.com (Rick Busdiecker) writes:
: >Do friend functions have access to the same entities that member
: >functions have?  In particular, do they have access to static member
: >function that are inherited?

: Yes, and yes. It's a compiler bug if a friend function can't access
: protected members of a publicly-derived class.

Is the answer really different if the derivation is not public?

--
/*----------------------------------------------------------------------*/
/* Bob Kline                                           CSI Technologies */
/* bkline@smtp.csof.com                        Corporate Software, Inc. */
/* voice: (703) 522-0820                            fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/




Author: rfb@lehman.com (Rick Busdiecker)
Date: Fri, 17 Jun 1994 16:45:01 GMT
Raw View
Do friend functions have access to the same entities that member
functions have?  In particular, do they have access to static member
function that are inherited?

    class Base
    {
     protected:
 static void target (void) {}
    };

    class Derived : public Base
    {
     private:
 static void helper (void) { target (); }
 friend void problem (void);
 friend void workaround (void);
    };

    void problem (void) { Derived::target (); }

    void workaround (void) { Derived::helper (); }

My compiler (SunOS 4.1.3 SparcWorks 2.0.1 C++) says:
  problem() cannot access Base::target(): protected  member

Incidentally, g++ and lcc both accept this as valid.

Clearly, it's not too difficult to generate workaround using a helper
function.  In fact, I think that this workaround demonstrates that the
restriction, if it is in fact a restriction, is silly.  The *only*
thing that it accomplishes is code obfuscation.

*My* reading of the ARM supports me :-)

  p. 248:

 11.4 Friends

 A friend of a class is a function that is not a member of the
 class but is permitted to use the private member names from
 the class.

This is possibly ambiguous because `from the class' might not imply
`from the base class via the class by means of inheritance.'

  p. 253

 11.5 Protected Member Access

 A friend or a member function of a derived class can access a
 protected static member of a base class.

This seems less ambiguous.  You would have to argue that `protected
static member' does not imply `protected static member function',
right?

So, who's the offender, the compiler or me (or the language definition)?

--
Rick Busdiecker <rfb@lehman.com>      Please do not send electronic junk mail!
  Lehman Brothers
  388 Greenwich Street      "One never notices what has been done; one can only
  New York, NY 10013         see what remains to be done." -- Marie Curie




Author: jason@cygnus.com (Jason Merrill)
Date: Sat, 18 Jun 1994 01:41:59 GMT
Raw View
>>>>> Rick Busdiecker <rfb@lehman.com> writes:

> So, who's the offender, the compiler or me (or the language definition)?

I vote for the compiler.

Jason