This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/8500: c++ bug


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]