r306905 - Fix PR 33189: Clang assertion on template destructor declaration
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 30 15:43:54 PDT 2017
Author: hubert.reinterpretcast
Date: Fri Jun 30 15:43:54 2017
New Revision: 306905
URL: http://llvm.org/viewvc/llvm-project?rev=306905&view=rev
Log:
Fix PR 33189: Clang assertion on template destructor declaration
Summary:
This patch aims to fix the bug reported at
https://bugs.llvm.org/show_bug.cgi?id=33189. Clang hits an assertion
when a template destructor declaration is present. This is caused by
later processing that does not expect to encounter a template when
looking at a destructor. The resolution is to treat the destructor as
being not declared when later processing is interested in the properties
of the destructor of a class.
Reviewers: rcraik, hubert.reinterpretcast, aaron.ballman, rsmith
Reviewed By: rsmith
Subscribers: rsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D33833
Patch by Kuang He!
Modified:
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/test/SemaTemplate/destructor-template.cpp
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=306905&r1=306904&r2=306905&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Jun 30 15:43:54 2017
@@ -1417,11 +1417,8 @@ CXXDestructorDecl *CXXRecordDecl::getDes
Context.getCanonicalType(ClassType));
DeclContext::lookup_result R = lookup(Name);
- if (R.empty())
- return nullptr;
- CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(R.front());
- return Dtor;
+ return R.empty() ? nullptr : dyn_cast<CXXDestructorDecl>(R.front());
}
bool CXXRecordDecl::isAnyDestructorNoReturn() const {
Modified: cfe/trunk/test/SemaTemplate/destructor-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/destructor-template.cpp?rev=306905&r1=306904&r2=306905&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/destructor-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/destructor-template.cpp Fri Jun 30 15:43:54 2017
@@ -86,3 +86,9 @@ namespace PR16852 {
template<typename T> decltype(S<T>().~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 <class T>
+ ~PR33189() { } // expected-error{{destructor cannot be declared as a template}}
+};
More information about the cfe-commits
mailing list