Bug 2330 - static_cast<>() to a private base is allowed
: static_cast<>() to a private base is allowed
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
: 2.95.3
: P3 normal
: 3.3.1
Assigned To: Not yet assigned to anyone
:
: accepts-invalid, monitored
:
:
  Show dependency treegraph
 
Reported: 2001-03-20 10:26 UTC by philippeb
Modified: 2003-08-06 17:36 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-23 12:42:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description philippeb 2001-03-20 10:26:01 UTC
static_cast<>() from a derived type to its private base is 
allowed, but shouldn't. dynamic_cast<>() is okay on its side.

Release:
2.95.3

Environment:
Debian Linux (Woody) on Intel

How-To-Repeat:
#include <iostream>

struct A
{
    void foo() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

struct B : private A
{
};

int main()
{
    B b;
    static_cast<A &>(b).foo();
}
Comment 1 Nathan Sidwell 2001-04-25 08:26:16 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed as a bug
Comment 2 Nathan Sidwell 2001-04-25 15:26:16 UTC
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, philippeb@corel.com
Cc:  
Subject: Re: c++/2330
Date: 25 Apr 2001 15:26:16 -0000

 Synopsis: static_cast<>() to a private base is allowed
 
 State-Changed-From-To: open->analyzed
 State-Changed-By: nathan
 State-Changed-When: Wed Apr 25 08:26:16 2001
 State-Changed-Why:
     confirmed as a bug
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2330&database=gcc

Comment 3 Wolfgang Bangerth 2002-11-08 09:07:23 UTC
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/2330: static_cast<>() to a private base is allowed
Date: Fri, 8 Nov 2002 09:07:23 -0600 (CST)

 This problem persists. It also appears with a C-style cast like 
 (Base*)derived_object, see PR 8500.
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                                www: http://www.ticam.utexas.edu/~bangerth
 
 

Comment 4 Giovanni Bajo 2003-04-14 05:48:00 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	<philippeb@corel.com>,
	<gcc-prs@gcc.gnu.org>
Cc: "Wolfgang Bangerth" <bangerth@ices.utexas.edu>
Subject: Re: c++/2330: [2003-01-01] static_cast<>() to a private base is allowed
Date: Mon, 14 Apr 2003 05:48:00 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=2330
 
 Reconfirmed 2.95 -> 3.4 20030413 (bump date please)
 
 Giovanni Bajo
Comment 5 Andrew Pinski 2003-06-15 18:48:52 UTC
still happens on the mainline (20030615).
Comment 6 Volker Reichelt 2003-06-26 10:00:46 UTC
Fixed on the 3.3 branch and mainline.
Probably by Mark's patch:

http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02907.html