1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 3 struct NonTrivial { 4 NonTrivial(NonTrivial&&); 5 }; 6 7 // A defaulted move constructor for a class X is defined as deleted if X has: 8 9 // -- a variant member with a non-trivial corresponding constructor 10 union DeletedNTVariant { 11 NonTrivial NT; 12 DeletedNTVariant(DeletedNTVariant&&); 13 }; 14 DeletedNTVariant::DeletedNTVariant(DeletedNTVariant&&) = default; // expected-error{{would delete}} 15 16 struct DeletedNTVariant2 { 17 union { 18 NonTrivial NT; 19 }; 20 DeletedNTVariant2(DeletedNTVariant2&&); 21 }; 22 DeletedNTVariant2::DeletedNTVariant2(DeletedNTVariant2&&) = default; // expected-error{{would delete}} 23 24 // -- a non-static data member of class type M (or array thereof) that cannot be 25 // copied because overload resolution results in an ambiguity or a function 26 // that is deleted or inaccessible 27 struct NoAccess { 28 NoAccess() = default; 29 private: 30 NoAccess(NoAccess&&); 31 32 friend struct HasAccess; 33 }; 34 35 struct HasNoAccess { 36 NoAccess NA; 37 HasNoAccess(HasNoAccess&&); 38 }; 39 HasNoAccess::HasNoAccess(HasNoAccess&&) = default; // expected-error{{would delete}} 40 41 struct HasAccess { 42 NoAccess NA; 43 HasAccess(HasAccess&&); 44 }; 45 HasAccess::HasAccess(HasAccess&&) = default; 46 47 struct Ambiguity { 48 Ambiguity(const Ambiguity&&); 49 Ambiguity(volatile Ambiguity&&); 50 }; 51 52 struct IsAmbiguous { 53 Ambiguity A; 54 IsAmbiguous(IsAmbiguous&&); 55 }; 56 IsAmbiguous::IsAmbiguous(IsAmbiguous&&) = default; // expected-error{{would delete}} 57 58 struct Deleted { 59 IsAmbiguous IA; 60 Deleted(Deleted&&); 61 }; 62 Deleted::Deleted(Deleted&&) = default; // expected-error{{would delete}} 63 64 // -- a direct or virtual base class B that cannot be moved because overload 65 // resolution results in an ambiguity or a function that is deleted or 66 // inaccessible 67 struct AmbiguousMoveBase : Ambiguity { 68 AmbiguousMoveBase(AmbiguousMoveBase&&); 69 }; 70 AmbiguousMoveBase::AmbiguousMoveBase(AmbiguousMoveBase&&) = default; // expected-error{{would delete}} 71 72 struct DeletedMoveBase : AmbiguousMoveBase { 73 DeletedMoveBase(DeletedMoveBase&&); 74 }; 75 DeletedMoveBase::DeletedMoveBase(DeletedMoveBase&&) = default; // expected-error{{would delete}} 76 77 struct InaccessibleMoveBase : NoAccess { 78 InaccessibleMoveBase(InaccessibleMoveBase&&); 79 }; 80 InaccessibleMoveBase::InaccessibleMoveBase(InaccessibleMoveBase&&) = default; // expected-error{{would delete}} 81 82 // -- any direct or virtual base class or non-static data member of a type with 83 // a destructor that is deleted or inaccessible 84 struct NoAccessDtor { 85 NoAccessDtor(NoAccessDtor&&); // expected-note{{copy constructor is implicitly deleted because 'NoAccessDtor' has a user-declared move constructor}} 86 private: 87 ~NoAccessDtor(); 88 friend struct HasAccessDtor; 89 }; 90 91 struct HasNoAccessDtor { 92 NoAccessDtor NAD; 93 HasNoAccessDtor(HasNoAccessDtor&&); 94 }; 95 HasNoAccessDtor::HasNoAccessDtor(HasNoAccessDtor&&) = default; // expected-error{{would delete}} 96 97 struct HasAccessDtor { 98 NoAccessDtor NAD; 99 HasAccessDtor(HasAccessDtor&&); 100 }; 101 HasAccessDtor::HasAccessDtor(HasAccessDtor&&) = default; 102 103 struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has a deleted copy constructor}} 104 }; 105 extern HasNoAccessDtorBase HNADBa; 106 HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}} 107 108 // The restriction on rvalue reference members applies to only the copy 109 // constructor. 110 struct RValue { 111 int &&ri = 1; // expected-warning {{binding reference member 'ri' to a temporary}} expected-note {{here}} 112 RValue(RValue&&); 113 }; 114 RValue::RValue(RValue&&) = default; 115 116 // -- a non-static data member or direct or virtual base class with a type that 117 // does not have a move constructor and is not trivially copyable 118 struct CopyOnly { 119 CopyOnly(const CopyOnly&); 120 }; 121 122 struct NonMove { 123 CopyOnly CO; 124 NonMove(NonMove&&); 125 }; 126 NonMove::NonMove(NonMove&&) = default; // ok under DR1402 127 128 struct Moveable { 129 Moveable(); 130 Moveable(Moveable&&); 131 }; 132 133 struct HasMove { 134 Moveable M; 135 HasMove(HasMove&&); 136 }; 137 HasMove::HasMove(HasMove&&) = default; 138 139 namespace DR1402 { 140 struct member { 141 member(); 142 member(const member&); 143 member& operator=(const member&); 144 ~member(); 145 }; 146 147 struct A { 148 member m_; 149 150 A() = default; 151 A(const A&) = default; 152 A& operator=(const A&) = default; 153 A(A&&) = default; 154 A& operator=(A&&) = default; 155 ~A() = default; 156 }; 157 158 // ok, A's explicitly-defaulted move operations copy m_. 159 void f() { 160 A a, b(a), c(static_cast<A&&>(a)); 161 a = b; 162 b = static_cast<A&&>(c); 163 } 164 } 165