r197509 - [ms-cxxabi] Don't do destructor check on declarations if the dtor is deleted
Hans Wennborg
hans at hanshq.net
Tue Dec 17 09:49:22 PST 2013
Author: hans
Date: Tue Dec 17 11:49:22 2013
New Revision: 197509
URL: http://llvm.org/viewvc/llvm-project?rev=197509&view=rev
Log:
[ms-cxxabi] Don't do destructor check on declarations if the dtor is deleted
We would previously emit redundant diagnostics for the following code:
struct S {
virtual ~S() = delete;
void operator delete(void*, int);
void operator delete(void*, double);
} s;
First we would check on ~S() and error about the ambigous delete functions,
and then we would error about using the deleted destructor.
If the destructor is deleted, there's no need to check it.
Also, move the check from Sema::ActOnFields to CheckCompleteCXXClass. These
are run at almost the same time, called from ActOnFinishCXXMemberSpecification.
However, CHeckCompleteCXXClass may mark a defaulted destructor as deleted, and
if that's the case we don't want to check it.
Differential Revision: http://llvm-reviews.chandlerc.com/D2421
Added:
cfe/trunk/test/SemaCXX/microsoft-dtor-lookup-cxx11.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=197509&r1=197508&r2=197509&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 17 11:49:22 2013
@@ -6332,7 +6332,7 @@ static FunctionDecl* CreateNewFunctionDe
// any translation unit may need to emit a deleting destructor.
if (SemaRef.Context.getTargetInfo().getCXXABI().isMicrosoft() &&
!Record->isDependentType() && Record->getDefinition() &&
- !Record->isBeingDefined()) {
+ !Record->isBeingDefined() && !NewDD->isDeleted()) {
SemaRef.CheckDestructor(NewDD);
}
@@ -12082,12 +12082,6 @@ void Sema::ActOnFields(Scope *S, SourceL
if (getLangOpts().CPlusPlus11)
AdjustDestructorExceptionSpec(CXXRecord,
CXXRecord->getDestructor());
-
- // The Microsoft ABI requires that we perform the destructor body
- // checks (i.e. operator delete() lookup) at every declaration, as
- // any translation unit may need to emit a deleting destructor.
- if (Context.getTargetInfo().getCXXABI().isMicrosoft())
- CheckDestructor(CXXRecord->getDestructor());
}
// Add any implicitly-declared members to this class.
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=197509&r1=197508&r2=197509&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Dec 17 11:49:22 2013
@@ -4469,6 +4469,15 @@ void Sema::CheckCompletedCXXClass(CXXRec
}
}
}
+
+ if (Record->hasUserDeclaredDestructor()) {
+ // The Microsoft ABI requires that we perform the destructor body
+ // checks (i.e. operator delete() lookup) in any translataion unit, as
+ // any translation unit may need to emit a deleting destructor.
+ if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+ !Record->getDestructor()->isDeleted())
+ CheckDestructor(Record->getDestructor());
+ }
}
// C++11 [dcl.constexpr]p8: A constexpr specifier for a non-static member
Added: cfe/trunk/test/SemaCXX/microsoft-dtor-lookup-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/microsoft-dtor-lookup-cxx11.cpp?rev=197509&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/microsoft-dtor-lookup-cxx11.cpp (added)
+++ cfe/trunk/test/SemaCXX/microsoft-dtor-lookup-cxx11.cpp Tue Dec 17 11:49:22 2013
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi microsoft -std=c++11 -verify %s
+
+struct S {
+ virtual ~S() = delete; // expected-note {{function has been explicitly marked deleted here}}
+ void operator delete(void*, int);
+ void operator delete(void*, double);
+} s; // expected-error {{attempt to use a deleted function}}
+
+struct T { // expected-note{{virtual destructor requires an unambiguous, accessible 'operator delete'}}
+ virtual ~T() = default; // expected-note {{explicitly defaulted function was implicitly deleted here}}
+ void operator delete(void*, int);
+ void operator delete(void*, double);
+} t; // expected-error {{attempt to use a deleted function}}
More information about the cfe-commits
mailing list