Insufficient access check for private static member in base class

View: New views
2 Messages — Rating Filter:   Alert me  

Insufficient access check for private static member in base class

by Peter A. Felvegi :: Rate this Message:

| View Threaded | Show Only this Message

Hello,

I've bumped into the following:

----8<----8<----8<----8<----
class Base
{
static
int foo;
};

#if 0
class Deriv : public Base
{
public:
int Foo() { return foo; }
};
#endif

template<typename T>
class DerivT : public Base
{
public:
int Foo() { return foo; }
};

void bar()
{
DerivT<void> dt;
dt.Foo();
}
----8<----8<----8<----8<----

All versions I've tried (4.4, 4.5, 4.6, 4.7) compiles the code. clang
gives proper diagnostic stating that Base::foo is private.

If base::foo is not static, gcc catches the error, too:
gccacbug.cpp: In member function ‘int DerivT<T>::Foo() [with T = void]’:
gccacbug.cpp:25: instantiated from here
gccacbug.cpp:4: error: ‘int Base::foo’ is private
gccacbug.cpp:19: error: within this context

If I enable the non-templated Deriv class, I get an error (twice):
gccacbug.cpp: In member function ‘int Deriv::Foo()’:
gccacbug.cpp:3:13: error: ‘int Base::foo’ is private
gccacbug.cpp:10:21: error: within this context
gccacbug.cpp:3:13: error: ‘int Base::foo’ is private
gccacbug.cpp:10:21: error: within this context

Searching bugzilla for 'static member access' didn't give any results.
Should I file a bug report?

Regards, Peter


Re: Insufficient access check for private static member in base class

by Ian Lance Taylor-3 :: Rate this Message:

| View Threaded | Show Only this Message

"Peter A. Felvegi" <petschy@...> writes:

> All versions I've tried (4.4, 4.5, 4.6, 4.7) compiles the code. clang
> gives proper diagnostic stating that Base::foo is private.
>
> If base::foo is not static, gcc catches the error, too:
> gccacbug.cpp: In member function ‘int DerivT<T>::Foo() [with T = void]’:
> gccacbug.cpp:25: instantiated from here
> gccacbug.cpp:4: error: ‘int Base::foo’ is private
> gccacbug.cpp:19: error: within this context
>
> If I enable the non-templated Deriv class, I get an error (twice):
> gccacbug.cpp: In member function ‘int Deriv::Foo()’:
> gccacbug.cpp:3:13: error: ‘int Base::foo’ is private
> gccacbug.cpp:10:21: error: within this context
> gccacbug.cpp:3:13: error: ‘int Base::foo’ is private
> gccacbug.cpp:10:21: error: within this context
>
> Searching bugzilla for 'static member access' didn't give any
> results. Should I file a bug report?

Looks like an instance of http://gcc.gnu.org/PR16617 ,
http://gcc.gnu.org/PR47346 , http://gcc.gnu.org/PR48078 , and friends.

Ian