diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -1476,7 +1476,8 @@ } else if (FunctionDecl *FN = dyn_cast(D)) { DC = FN; } else if (TemplateDecl *TD = dyn_cast(D)) { - DC = cast(TD->getTemplatedDecl()); + if (isa(TD->getTemplatedDecl())) + DC = cast(TD->getTemplatedDecl()); } EffectiveContext EC(DC); diff --git a/clang/test/SemaCXX/cxx14-access.cpp b/clang/test/SemaCXX/cxx14-access.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/cxx14-access.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s + +namespace NoCrashOnDelayedAccessCheck { +class Foo { + class Private; // expected-note {{declared private here}} +}; + +struct Bar {}; + +template +Foo::Private Bar::ABC; // expected-error {{no member named 'ABC' in 'NoCrashOnDelayedAccessCheck::Bar'}} \ + expected-error {{'Private' is a private member of}} +}