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

philippeb@corel.com philippeb@corel.com
Tue Mar 20 10:26:00 GMT 2001


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



More information about the Gcc-bugs mailing list