Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -10510,9 +10510,16 @@ // The scope type is now known to be a valid nested name specifier // component. Tack it on to the end of the nested name specifier. - if (ScopeType) - SS.Extend(SemaRef.Context, SourceLocation(), - ScopeType->getTypeLoc(), CCLoc); + if (ScopeType) { + if (!ScopeType->getType()->getAs()) { + getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), + diag::err_expected_class_or_namespace) + << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; + return ExprError(); + } + SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), + CCLoc); + } SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. return getSema().BuildMemberReferenceExpr(Base, BaseType, 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); +} +