1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 3struct Trivial {}; 4struct NonTrivial { 5 NonTrivial(const NonTrivial&); 6}; 7 8// A defaulted copy constructor for a class X is defined as deleted if X has: 9 10// -- a variant member with a non-trivial corresponding constructor 11union DeletedNTVariant { 12 NonTrivial NT; // expected-note{{copy constructor of 'DeletedNTVariant' is implicitly deleted because variant field 'NT' has a non-trivial copy constructor}} 13 DeletedNTVariant(); 14}; 15DeletedNTVariant DVa; 16DeletedNTVariant DVb(DVa); // expected-error{{call to implicitly-deleted copy constructor}} 17 18struct DeletedNTVariant2 { 19 union { 20 NonTrivial NT; // expected-note{{copy constructor of 'DeletedNTVariant2' is implicitly deleted because variant field 'NT' has a non-trivial copy constructor}} 21 }; 22 DeletedNTVariant2(); 23}; 24DeletedNTVariant2 DV2a; 25DeletedNTVariant2 DV2b(DV2a); // expected-error{{call to implicitly-deleted copy constructor}} 26 27// -- a non-static data member of class type M (or array thereof) that cannot be 28// copied because overload resolution results in an ambiguity or a function 29// that is deleted or inaccessible 30struct NoAccess { 31 NoAccess() = default; 32private: 33 NoAccess(const NoAccess&); 34 35 friend struct HasAccess; 36}; 37 38struct HasNoAccess { 39 NoAccess NA; // expected-note{{copy constructor of 'HasNoAccess' is implicitly deleted because field 'NA' has an inaccessible copy constructor}} 40}; 41HasNoAccess HNAa; 42HasNoAccess HNAb(HNAa); // expected-error{{call to implicitly-deleted copy constructor}} 43 44struct HasAccess { 45 NoAccess NA; 46}; 47 48HasAccess HAa; 49HasAccess HAb(HAa); 50 51struct NonConst { 52 NonConst(NonConst&); 53}; 54struct Ambiguity { 55 Ambiguity(const Ambiguity&); 56 Ambiguity(volatile Ambiguity&); 57}; 58 59struct IsAmbiguous { 60 NonConst NC; 61 Ambiguity A; // expected-note 2{{copy constructor of 'IsAmbiguous' is implicitly deleted because field 'A' has multiple copy constructors}} 62 IsAmbiguous(); 63}; 64IsAmbiguous IAa; 65IsAmbiguous IAb(IAa); // expected-error{{call to implicitly-deleted copy constructor}} 66 67struct Deleted { 68 IsAmbiguous IA; // expected-note{{copy constructor of 'Deleted' is implicitly deleted because field 'IA' has a deleted copy constructor}} 69}; 70Deleted Da; 71Deleted Db(Da); // expected-error{{call to implicitly-deleted copy constructor}} 72 73// It's implied (but not stated) that this also applies in the case where 74// overload resolution would fail. 75struct VolatileMember { 76 volatile Trivial vm; // expected-note {{has no copy}} 77} vm1, vm2(vm1); // expected-error {{deleted}} 78 79// -- a direct or virtual base class B that cannot be copied because overload 80// resolution results in an ambiguity or a function that is deleted or 81// inaccessible 82struct AmbiguousCopyBase : Ambiguity { // expected-note 2{{copy constructor of 'AmbiguousCopyBase' is implicitly deleted because base class 'Ambiguity' has multiple copy constructors}} 83 NonConst NC; 84}; 85extern AmbiguousCopyBase ACBa; 86AmbiguousCopyBase ACBb(ACBa); // expected-error {{deleted copy constructor}} 87 88struct DeletedCopyBase : AmbiguousCopyBase {}; // expected-note {{copy constructor of 'DeletedCopyBase' is implicitly deleted because base class 'AmbiguousCopyBase' has a deleted copy constructor}} 89extern DeletedCopyBase DCBa; 90DeletedCopyBase DCBb(DCBa); // expected-error {{deleted copy constructor}} 91 92struct InaccessibleCopyBase : NoAccess {}; // expected-note {{copy constructor of 'InaccessibleCopyBase' is implicitly deleted because base class 'NoAccess' has an inaccessible copy constructor}} 93extern InaccessibleCopyBase ICBa; 94InaccessibleCopyBase ICBb(ICBa); // expected-error {{deleted copy constructor}} 95 96// -- any direct or virtual base class or non-static data member of a type with 97// a destructor that is deleted or inaccessible 98struct NoAccessDtor { 99private: 100 ~NoAccessDtor(); 101 friend struct HasAccessDtor; 102}; 103 104struct HasNoAccessDtor { 105 NoAccessDtor NAD; // expected-note{{copy constructor of 'HasNoAccessDtor' is implicitly deleted because field 'NAD' has an inaccessible destructor}} 106 HasNoAccessDtor(); 107 ~HasNoAccessDtor(); 108}; 109HasNoAccessDtor HNADa; 110HasNoAccessDtor HNADb(HNADa); // expected-error{{call to implicitly-deleted copy constructor}} 111 112struct HasAccessDtor { 113 NoAccessDtor NAD; 114}; 115HasAccessDtor HADa; 116HasAccessDtor HADb(HADa); 117 118struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has an inaccessible destructor}} 119}; 120extern HasNoAccessDtorBase HNADBa; 121HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}} 122 123// -- a non-static data member of rvalue reference type 124struct RValue { 125 int && ri = 1; // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}} 126 // expected-warning@-1{{binding reference member 'ri' to a temporary}} expected-note@-1 {{here}} 127}; 128RValue RVa; 129RValue RVb(RVa); // expected-error{{call to implicitly-deleted copy constructor}} 130 131namespace PR13381 { 132 struct S { 133 S(const S&); 134 S(const volatile S&) = delete; // expected-note{{deleted here}} 135 }; 136 struct T { 137 volatile S s; // expected-note{{field 's' has a deleted copy constructor}} 138 }; 139 T &f(); 140 T t = f(); // expected-error{{call to implicitly-deleted copy constructor}} 141} 142 143namespace Mutable { 144 struct A { 145 A(const A &); 146 A(A &) = delete; // expected-note {{deleted here}} 147 }; 148 149 struct B { 150 A a; 151 B(const B &); 152 }; 153 B::B(const B &) = default; 154 155 struct C { 156 mutable A a; // expected-note {{deleted because field 'a' has a deleted copy constructor}} 157 C(const C &); 158 }; 159 C::C(const C &) = default; // expected-error{{would delete}} 160} 161