public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: <Harald.Soleng@nr.no>
To: gcc-gnats@gcc.gnu.org
Subject: c++/8500: c++ bug
Date: Fri, 08 Nov 2002 02:46:00 -0000	[thread overview]
Message-ID: <200211081043.LAA08404@lyra.nr.no> (raw)


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


                 reply	other threads:[~2002-11-08 10:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200211081043.LAA08404@lyra.nr.no \
    --to=harald.soleng@nr.no \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).