Index: lib/Sema/SemaCXXScopeSpec.cpp =================================================================== --- lib/Sema/SemaCXXScopeSpec.cpp +++ lib/Sema/SemaCXXScopeSpec.cpp @@ -141,9 +141,9 @@ case NestedNameSpecifier::TypeSpec: case NestedNameSpecifier::TypeSpecWithTemplate: { - const TagType *Tag = NNS->getAsType()->getAs(); - assert(Tag && "Non-tag type in nested-name-specifier"); - return Tag->getDecl(); + if (const auto *Tag = NNS->getAsType()->getAs()) + return Tag->getDecl(); + return nullptr; } case NestedNameSpecifier::Global: Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -597,6 +597,12 @@ // If the member name was a qualified-id, look into the // nested-name-specifier. DC = SemaRef.computeDeclContext(SS, false); + if (!DC) { + SemaRef.Diag(SS.getBeginLoc(), diag::err_expected_class_or_namespace) + << QualType(SS.getScopeRep()->getAsType(), /*Quals*/ 0) + << SemaRef.getLangOpts().CPlusPlus; + return true; + } if (SemaRef.RequireCompleteDeclContext(SS, DC)) { SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag) Index: test/SemaTemplate/instantiate-non-dependent-types.cpp =================================================================== --- test/SemaTemplate/instantiate-non-dependent-types.cpp +++ test/SemaTemplate/instantiate-non-dependent-types.cpp @@ -11,4 +11,34 @@ typedef instantiate<&X1::member> i; // expected-note{{in instantiation of}} }; -X2 x; +X2 x; + +template class C { +public: + int i; + void f(T &t) { + T *q = new T(); + t.T::~T(); + q->~T(); + // expected-error@+1 {{'int' is not a class, namespace, or scoped enumeration}} + q->A::~A(); + // expected-error@+1 {{no member named '~int' in 'Q'}} + q->~A(); + + delete q; + } +}; + +class Q { +public: + Q() {} + ~Q() {} +}; + +C dummy; +int main() { + Q qinst; + // expected-note@+1 {{in instantiation of member function 'C::f' requested here}} + dummy.f(qinst); +} +