From: Nico Weber Date: Mon, 23 Jan 2012 03:19:29 +0000 (+0000) Subject: In ms mode, a move assignment operator shouldn't mark a copy ctor as deleted. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afcc96a20029ac9009feefbc555a4f9d923e3e06;p=clang In ms mode, a move assignment operator shouldn't mark a copy ctor as deleted. MSVC2010's pair class has a move assignment operator but no explicit copy constructor, which makes it unusable without this change. For symmetry, let move copy constructors not mark the default assignment operator as deleted either. Both changes match cl.exe's behavior. Fixes pr11826. Also update the standard excerpt to point to the right paragraph. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148675 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 6a24d9e430..1371b35ed4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -7846,12 +7846,14 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) { PushOnScopeChains(CopyAssignment, S, false); ClassDecl->addDecl(CopyAssignment); - // C++0x [class.copy]p18: - // ... If the class definition declares a move constructor or move - // assignment operator, the implicitly declared copy assignment operator is - // defined as deleted; ... - if (ClassDecl->hasUserDeclaredMoveConstructor() || - ClassDecl->hasUserDeclaredMoveAssignment() || + // C++0x [class.copy]p19: + // .... If the class definition does not explicitly declare a copy + // assignment operator, there is no user-declared move constructor, and + // there is no user-declared move assignment operator, a copy assignment + // operator is implicitly declared as defaulted. + if ((ClassDecl->hasUserDeclaredMoveConstructor() && + !getLangOptions().MicrosoftExt) || + ClassDecl->hasUserDeclaredMoveAssignment() && ShouldDeleteCopyAssignmentOperator(CopyAssignment)) CopyAssignment->setDeletedAsWritten(); @@ -8749,12 +8751,14 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor( PushOnScopeChains(CopyConstructor, S, false); ClassDecl->addDecl(CopyConstructor); - // C++0x [class.copy]p7: - // ... If the class definition declares a move constructor or move - // assignment operator, the implicitly declared constructor is defined as - // deleted; ... + // C++11 [class.copy]p8: + // ... If the class definition does not explicitly declare a copy + // constructor, there is no user-declared move constructor, and there is no + // user-declared move assignment operator, a copy constructor is implicitly + // declared as defaulted. if (ClassDecl->hasUserDeclaredMoveConstructor() || - ClassDecl->hasUserDeclaredMoveAssignment() || + (ClassDecl->hasUserDeclaredMoveAssignment() && + !getLangOptions().MicrosoftExt) || ShouldDeleteSpecialMember(CopyConstructor, CXXCopyConstructor)) CopyConstructor->setDeletedAsWritten(); diff --git a/test/SemaCXX/microsoft-cxx0x.cpp b/test/SemaCXX/microsoft-cxx0x.cpp index 82966d8a44..a0dbb75e07 100644 --- a/test/SemaCXX/microsoft-cxx0x.cpp +++ b/test/SemaCXX/microsoft-cxx0x.cpp @@ -7,4 +7,25 @@ struct A { int b = 3; A var = { b }; // expected-warning {{ cannot be narrowed }} expected-note {{override}} +namespace PR11826 { + struct pair { + pair(int v) { } + void operator=(pair&& rhs) { } + }; + void f() { + pair p0(3); + pair p = p0; + } +} +namespace PR11826_for_symmetry { + struct pair { + pair(int v) { } + pair(pair&& rhs) { } + }; + void f() { + pair p0(3); + pair p(4); + p = p0; + } +}