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]

c++/2330: static_cast<>() to a private base is allowed



>Number:         2330
>Category:       c++
>Synopsis:       static_cast<>() to a private base is allowed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 20 10:26:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     gcc
>Release:        2.95.3
>Organization:
>Environment:
Debian Linux (Woody) on Intel
>Description:
static_cast<>() from a derived type to its private base is 
allowed, but shouldn't. dynamic_cast<>() is okay on its side.
>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();
}
>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]