Index: lib/Sema/SemaAccess.cpp =================================================================== --- lib/Sema/SemaAccess.cpp +++ lib/Sema/SemaAccess.cpp @@ -475,8 +475,8 @@ // If the class's context can't instantiate to the friend's // context, it can't be a dependent match. - if (!MightInstantiateTo(S, CTD->getDeclContext(), - Friend->getDeclContext())) + if (Friend->getDeclContext()->isDependentContext() || + !MightInstantiateTo(S, CTD->getDeclContext(), Friend->getDeclContext())) continue; // Otherwise, it's a dependent match. Index: test/SemaTemplate/crash-bug-27258.cpp =================================================================== --- /dev/null +++ test/SemaTemplate/crash-bug-27258.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +template +struct AA { + template + struct B {}; +}; + +class C { + int i; // expected-note{{implicitly declared private here}} + template + template + friend struct AA::B; +}; + +struct A { + template + struct B { + void f() { + C c; + c.i; // expected-error{{'i' is a private member of 'C'}} expected-warning{{expression result unused}} + } + }; +};