struct A {}; template <typename> struct I; struct P { virtual ~P(); }; template <typename> struct B; struct J : P { friend I<B<double>>; virtual B<int> &foo(int); }; struct L : virtual J, virtual P {}; struct C { P &c; C(P &p1) : c(p1) {} }; template <typename B> struct I : C { typedef typename B::template F<0>::t R; J &c; I(J &p1) : C(p1), c(p1) {} R &bar(int) { c.foo(0); } }; template <int, typename T> struct K : A { typedef typename T::S S; bool baz(const int &, I<S> &p2, I<S> &p3); }; struct D { virtual void foo(); }; template <typename> struct B { template <int> struct F { typedef int t; }; }; struct M : P, virtual public J {}; struct N : public M, virtual L {}; struct O : public N, D { O(int); }; struct G { typedef B<double> S; template <int> struct H { typedef O t; }; }; template <int N, typename T> bool K<N, T>::baz(const int &, I<S> &p2, I<S> &p3) { typedef typename T::template H<0>::t W; typedef typename S::template F<0>::t R; W a(0); I<S> b(a); R &c = b.bar(0); } template struct K<0, G>; with -std=c++0x -O2 started to ICE with r201836 and while the exact spot where it ICEd changed several times, it continues to ICE with current 4.9 branch and latest trunk.
Also fixed by fix for PR60871 *** This bug has been marked as a duplicate of bug 60871 ***