public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/8500: c++ bug
@ 2002-11-08  2:46 Harald.Soleng
  0 siblings, 0 replies; only message in thread
From: Harald.Soleng @ 2002-11-08  2:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8500
>Category:       c++
>Synopsis:       Allows cast to private base class
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 08 02:46:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Harald H. Soleng
>Release:        3.1.1
>Organization:
Norwegian Computing Centre
>Environment:
System: SunOS lyra 5.8 Generic_108528-12 sun4u sparc SUNW,Sun-Fire-280R
Architecture: sun4

	
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ./configure --prefix=/local/gcc3.1.1
>Description:
	The compiler admits static_cast to convert from a derived class to
	a private base class: See code below.  


#include <iostream>
using namespace std;
class Base
{
   public:
      Base() : _data(999) {}
      int  Data() const {return _data;}
   private:
      int _data;
};

class Derived : private Base
{
   public:
      Derived () : Base() {}
};


int main(void) {
  

   Derived* d1 = new Derived;
   Base* b1 = (Base*) d1;
   int i = b1->Data(); 
   cout << "We got it: " << i << endl;

   
   Base* b2 = static_cast<Base*>(d1);
   int j = b2 -> Data(); 
   cout << "We got it: " << j << endl;

}

>How-To-Repeat:
	
>Fix:
	

















>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-11-08 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-08  2:46 c++/8500: c++ bug Harald.Soleng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).