Index: lib/AST/DeclCXX.cpp =================================================================== --- lib/AST/DeclCXX.cpp +++ lib/AST/DeclCXX.cpp @@ -1417,11 +1417,8 @@ Context.getCanonicalType(ClassType)); DeclContext::lookup_result R = lookup(Name); - if (R.empty()) - return nullptr; - CXXDestructorDecl *Dtor = cast(R.front()); - return Dtor; + return R.empty() ? nullptr : dyn_cast(R.front()); } bool CXXRecordDecl::isAnyDestructorNoReturn() const { Index: test/SemaTemplate/destructor-template.cpp =================================================================== --- test/SemaTemplate/destructor-template.cpp +++ test/SemaTemplate/destructor-template.cpp @@ -86,3 +86,9 @@ template decltype(S().~S()) f(); // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} void g() { f(); } // expected-error {{no matching function for call to 'f'}} } + +class PR33189 +{ + template + ~PR33189() { } // expected-error{{destructor cannot be declared as a template}} +};