https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67407
--- Comment #2 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- markus@x4 tmp % cat b.ii template <class> class A; template <class> struct B; template <class X> struct B<A<X> > { static int check () { A<X> a; a.m_class->m_object; } }; template <class T> class A { public: template <class X> bool operator== (const X &) const; T *m_class; }; template <class T> template <class X> bool A<T>::operator== (const X &) const { B<X>::check; } class C { protected: template <class> friend struct B; void *m_object; }; class F : virtual C { }; class G : virtual public C { }; class H : F, public G { }; class D { void onBusMessage (const A<int> &); A<H> m_pipeline; }; void D::onBusMessage (const A<int> &p1) { p1 == m_pipeline; } markus@x4 tmp % g++ -c b.ii b.ii: In instantiation of ‘static int B<A<X> >::check() [with X = H]’: b.ii:23:3: required from ‘bool A< <template-parameter-1-1> >::operator==(const X&) const [with X = A<H>; T = int]’ b.ii:48:9: required from here b.ii:9:5: internal compiler error: in friend_accessible_p, at cp/search.c:847 a.m_class->m_object; ^ 0x75973d friend_accessible_p ../../gcc/gcc/cp/search.c:847 0x759703 friend_accessible_p ../../gcc/gcc/cp/search.c:839 0x7596c2 friend_accessible_p ../../gcc/gcc/cp/search.c:822 0x759942 dfs_accessible_post ../../gcc/gcc/cp/search.c:907 0x756f66 dfs_walk_once_accessible_r ../../gcc/gcc/cp/search.c:1872 0x75708c dfs_walk_once_accessible_r ../../gcc/gcc/cp/search.c:1863 0x75708c dfs_walk_once_accessible_r ../../gcc/gcc/cp/search.c:1863 0x7571cc dfs_walk_once_accessible ../../gcc/gcc/cp/search.c:1891 0x758c69 accessible_p(tree_node*, tree_node*, bool) ../../gcc/gcc/cp/search.c:1015 0x5c5141 enforce_access(tree_node*, tree_node*, tree_node*, int) ../../gcc/gcc/cp/call.c:6091 0x76ea27 perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int) ../../gcc/gcc/cp/semantics.c:337 0x758585 lookup_member(tree_node*, tree_node*, int, bool, int) ../../gcc/gcc/cp/search.c:1337 0x72f47b finish_class_member_access_expr(tree_node*, tree_node*, bool, int) ../../gcc/gcc/cp/typeck.c:2782 0x643920 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc/gcc/cp/pt.c:16098 0x635a40 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc/gcc/cp/pt.c:15031 0x636422 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc/gcc/cp/pt.c:14442 0x634f43 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc/gcc/cp/pt.c:14428 0x63521b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc/gcc/cp/pt.c:14614 0x6334f5 instantiate_decl(tree_node*, int, bool) ../../gcc/gcc/cp/pt.c:21158 0x678689 instantiate_pending_templates(int) ../../gcc/gcc/cp/pt.c:21275 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.