The code: template<typename T> struct b1 { protected: void inc() {} T* dummy; }; template<typename T, template<typename>class F> struct b2 { void f() { F<T>* s = static_cast<F<T>*>(this); s->inc(); } };
template<typename T> struct G : public b1<T>, public b2<T, G> { }; int main() { G<int> g; g.f(); } gets you: ~/ootbc/members/src$ g++ foo.cc foo.cc: In member function `void b2<T, F>::f() [with T = int, F = G]': foo.cc:22: instantiated from here foo.cc:4: error: `void b1<T>::inc() [with T = int]' is protected foo.cc:11: error: within this context The access to "inc" is "s->inc()". "s" is a "F<T>", which after parameter substitution is a "G<int>". "b2<T, G>" is a public base of G, which after substitution means that "b2<int, G>" is a public base of "G<int>" and so is also a public base of "s". Hence the protected member "b2<int, G>::inc" should be visible via "s", but is not. Ivan -- Summary: Static_cast loses access to protected Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24592