From: Richard Smith Date: Sat, 24 Dec 2011 21:56:24 +0000 (+0000) Subject: Always implicitly declare move assignment operations for dynamic classes, in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b701d3d0b20b00cb3b1d874a23f1e8d450f989f8;p=clang Always implicitly declare move assignment operations for dynamic classes, in case they override virtual functions from a base class. Also fix -print-stats counting of move assignment/construction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147258 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 7f743f50f3..ad327ac755 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4981,6 +4981,9 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { if (!ClassDecl->hasUserDeclaredCopyConstructor()) ++ASTContext::NumImplicitCopyConstructors; + if (getLangOptions().CPlusPlus0x && ClassDecl->needsImplicitMoveConstructor()) + ++ASTContext::NumImplicitMoveConstructors; + if (!ClassDecl->hasUserDeclaredCopyAssignment()) { ++ASTContext::NumImplicitCopyAssignmentOperators; @@ -4992,6 +4995,14 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { DeclareImplicitCopyAssignment(ClassDecl); } + if (getLangOptions().CPlusPlus0x && ClassDecl->needsImplicitMoveAssignment()){ + ++ASTContext::NumImplicitMoveAssignmentOperators; + + // Likewise for the move assignment operator. + if (ClassDecl->isDynamicClass()) + DeclareImplicitMoveAssignment(ClassDecl); + } + if (!ClassDecl->hasUserDeclaredDestructor()) { ++ASTContext::NumImplicitDestructors; diff --git a/test/CodeGenCXX/virtual-implicit-move-assignment.cpp b/test/CodeGenCXX/virtual-implicit-move-assignment.cpp new file mode 100644 index 0000000000..d8ac1ed4c4 --- /dev/null +++ b/test/CodeGenCXX/virtual-implicit-move-assignment.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm -std=c++11 -o - %s | FileCheck %s + +struct D; +struct B { + virtual D &operator=(D&&) = 0; +}; +struct D : B { D(); virtual void a(); }; +void D::a() {} +D d; + +// CHECK: @_ZTV1D = {{.*}} @_ZN1DaSEOS_ +// CHECK: define linkonce_odr {{.*}} @_ZN1DaSEOS_