c++/1616: gcc allows access to private variable in enclosing scope

wolfgang.bangerth@iwr.uni-heidelberg.de wolfgang.bangerth@iwr.uni-heidelberg.de
Sun Apr 1 00:00:00 GMT 2001


>Number:         1616
>Category:       c++
>Synopsis:       gcc allows access to private variable in enclosing scope
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 11 04:06:04 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Bangerth
>Release:        unknown-1.0
>Organization:
>Environment:
Sun, Linux
>Description:
this compiles fine, to my astonishment:
class X {
    static int i;
    
    struct Y {
        int f() { return i; };
    };
};

Note that X::Y::f accesses the (private) static variable from X, which I
think it shouldn't be able to do (why is this variable visible in
the scope of X::Y::f at all?). I always thought, nested scopes are not
by default friends of the enclosing one (after all, f() can't call private
functions in X as well).
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-prs mailing list