🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1804

g++ 1.34.1 & private base classes

#1804
From: Kim Coleman
Date: Tue, 28 Mar 1989 17:59
44 lines
1927 bytes
//  Test that compiler correctly handles private base classes. In particular,
//  an implicit conversion from a derived pointer to a base pointer should
//  only be made when the base class is public. See Stroustrap, p. 197.
//
//  Actually, g++ carries this rule even farther and performs implicit
//  conversions on objects and references as well as pointers. Though this
//  doesn't conform to The Book, if you're going to do this, it should
//  follow the same rules as pointers regarding private base classes.
//  As demonstrated below, this is only partially true.

class base {
    int i;
public:
    base()   {i = 0;}
    base (int x)  {i = x;}
    do_something (base& param) {;}
};

class derived : base {
    int j;
public:
     derived() {j = 0;}
};

main()
{
   base     base_obj;
   derived  derived_obj;

      //
      // The following statements should be in error on one hand because
      // you can only perform implicit pointer conversions between derived
      // and base class objects. However, even if you accept this behavior,
      // they should still be in error because <base> is private.
      //
   base_obj = derived_obj;                // g++ 1.34.1 only catches this
   base_obj.do_something (derived_obj);   // should also be an error
}

-------------------------------------
Kim Coleman
Data General Corp., Research Triangle Park, NC
{the world}!mcnc!rti!dg-rtp!coleman
Technical Details
Message-ID: <4611@xyzzy.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu-cs!ncsuvx!mcnc!rti!xyzzy!bert!coleman

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu-cs!ncsuvx!mcnc!rti!xyzzy!bert!coleman
From: coleman@bert.dg.com (Kim Coleman)
Newsgroups: gnu.g++.bug
Subject: g++ 1.34.1 & private base classes
Summary: g++ not restrictive enough
Keywords: references
Message-ID: <4611@xyzzy.UUCP>
Date: 28 Mar 89 17:59:32 GMT
Sender: usenet@xyzzy.UUCP
Reply-To: coleman@bert.dg.com (Kim Coleman)
Distribution: gnu
Organization: Data General Corporation, Research Triangle Park, NC.
Lines: 43