Index: lib/Sema/SemaAccess.cpp =================================================================== --- lib/Sema/SemaAccess.cpp +++ lib/Sema/SemaAccess.cpp @@ -1487,7 +1487,7 @@ if (!DC->isFunctionOrMethod()) DC = FN; } else if (TemplateDecl *TD = dyn_cast(D)) { - DC = dyn_cast(TD->getTemplatedDecl()); + DC = cast(TD->getTemplatedDecl()); } EffectiveContext EC(DC); Index: test/SemaCXX/access.cpp =================================================================== --- test/SemaCXX/access.cpp +++ test/SemaCXX/access.cpp @@ -35,24 +35,74 @@ // PR15209 namespace PR15209 { - class A { - typedef int I; // expected-note {{implicitly declared private here}} - template friend struct B; - template struct C; - template friend struct E; - template class T> friend struct TT; - static constexpr int x = 0; - }; - template struct B { }; + namespace alias_templates { + template struct U { }; + template using W = U; - template struct A::C { }; + class A { + typedef int I; + static constexpr I x = 0; // expected-note {{implicitly declared private here}} + static constexpr I y = 42; // expected-note {{implicitly declared private here}} + friend W; + }; - template struct D { }; // expected-error {{'I' is a private member of 'PR15209::A'}} + template + struct U { + int v_; + // the following will trigger for U instantiation, via W + U() : v_(A::x) { } // expected-error {{'x' is a private member of 'PR15209::alias_templates::A'}} + }; - template struct E { }; + template + struct U { + int v_; + U() : v_(A::y) { } // expected-error {{'y' is a private member of 'PR15209::alias_templates::A'}} + }; - template class T> struct TT { - T t; - }; - template struct TT; + template struct U; // expected-note {{in instantiation of member function 'PR15209::alias_templates::U::U' requested here}} + + void f() + { + W(); + // we should issue diagnostics for the following + W(); // expected-note {{in instantiation of member function 'PR15209::alias_templates::U::U' requested here}} + } + } + + namespace templates { + class A { + typedef int I; // expected-note {{implicitly declared private here}} + static constexpr I x = 0; // expected-note {{implicitly declared private here}} + + template friend struct B; + template struct C; + template class T> friend struct TT; + template friend void funct(T); + }; + template struct B { }; + + template struct A::C { }; + + template class T> struct TT { + T t; + }; + + template struct TT; + template struct D { }; // expected-error {{'I' is a private member of 'PR15209::templates::A'}} + template struct TT; + + // function template case + template + void funct(T) + { + (void)A::x; + } + + template void funct(int); + + void f() + { + (void)A::x; // expected-error {{'x' is a private member of 'PR15209::templates::A'}} + } + } }