This code based on the example in [class.access]/6 is rejected: class A { typedef int I; // private member template<int> struct Q; template<int> friend struct R; protected: struct B { }; }; template<A::I> struct A::Q { }; template<A::I> struct R { }; struct D: A::B, A { }; t.cc:2:15: error: ‘typedef int A::I’ is private typedef int I; // private member ^ t.cc:8:13: error: within this context template<A::I> struct A::Q { }; ^ t.cc:2:15: error: ‘typedef int A::I’ is private typedef int I; // private member ^ t.cc:9:13: error: within this context template<A::I> struct R { }; ^ t.cc:6:10: error: ‘struct A::B’ is protected struct B { }; ^ t.cc:10:14: error: within this context struct D: A::B, A { }; ^ http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#580 clarifies that access checking of the template parameters should be delayed until the context is known.
*** Bug 111872 has been marked as a duplicate of this bug. ***