From: Aaron Ballman Date: Wed, 16 Jan 2013 23:39:10 +0000 (+0000) Subject: Fixes crash when illegal function definitions are deleted or defaulted. Fixes PR14577. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afb7ce3f877594362381926eaeac8ed6bbe18069;p=clang Fixes crash when illegal function definitions are deleted or defaulted. Fixes PR14577. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172676 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 5650781893..36b2043def 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -10815,7 +10815,7 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D, void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) { AdjustDeclIfTemplate(Dcl); - FunctionDecl *Fn = dyn_cast(Dcl); + FunctionDecl *Fn = dyn_cast_or_null(Dcl); if (!Fn) { Diag(DelLoc, diag::err_deleted_non_function); return; @@ -10835,7 +10835,7 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) { } void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) { - CXXMethodDecl *MD = dyn_cast(Dcl); + CXXMethodDecl *MD = dyn_cast_or_null(Dcl); if (MD) { if (MD->getParent()->isDependentType()) { diff --git a/test/SemaCXX/cxx0x-defaulted-functions.cpp b/test/SemaCXX/cxx0x-defaulted-functions.cpp index ce7ee672ea..3ad3a447f8 100644 --- a/test/SemaCXX/cxx0x-defaulted-functions.cpp +++ b/test/SemaCXX/cxx0x-defaulted-functions.cpp @@ -149,3 +149,24 @@ namespace PR13527 { Y &Y::operator=(Y&&) = default; // expected-error {{definition of explicitly defaulted}} Y::~Y() = default; // expected-error {{definition of explicitly defaulted}} } + +namespace PR14577 { + template + struct Outer { + template + struct Inner1 { + ~Inner1(); + }; + + template + struct Inner2 { + ~Inner2(); + }; + }; + + template + Outer::Inner1::~Inner1() = delete; // expected-error {{nested name specifier 'Outer::Inner1::' for declaration does not refer into a class, class template or class template partial specialization}} expected-error {{only functions can have deleted definitions}} + + template + Outer::Inner2::~Inner2() = default; // expected-error {{nested name specifier 'Outer::Inner2::' for declaration does not refer into a class, class template or class template partial specialization}} expected-error {{only special member functions may be defaulted}} +}