mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-13 23:36:05 +00:00
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. llvm-svn: 148675
This commit is contained in:
parent
844f945963
commit
94e746d5e5
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user