| 1 |
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
struct Trivial {}; |
| 4 |
struct 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 |
| 11 |
union 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 |
}; |
| 15 |
DeletedNTVariant DVa; |
| 16 |
DeletedNTVariant DVb(DVa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 17 |
|
| 18 |
struct 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 |
}; |
| 24 |
DeletedNTVariant2 DV2a; |
| 25 |
DeletedNTVariant2 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 |
| 30 |
struct NoAccess { |
| 31 |
NoAccess() = default; |
| 32 |
private: |
| 33 |
NoAccess(const NoAccess&); |
| 34 |
|
| 35 |
friend struct HasAccess; |
| 36 |
}; |
| 37 |
|
| 38 |
struct HasNoAccess { |
| 39 |
NoAccess NA; // expected-note{{copy constructor of 'HasNoAccess' is implicitly deleted because field 'NA' has an inaccessible copy constructor}} |
| 40 |
}; |
| 41 |
HasNoAccess HNAa; |
| 42 |
HasNoAccess HNAb(HNAa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 43 |
|
| 44 |
struct HasAccess { |
| 45 |
NoAccess NA; |
| 46 |
}; |
| 47 |
|
| 48 |
HasAccess HAa; |
| 49 |
HasAccess HAb(HAa); |
| 50 |
|
| 51 |
struct NonConst { |
| 52 |
NonConst(NonConst&); |
| 53 |
}; |
| 54 |
struct Ambiguity { |
| 55 |
Ambiguity(const Ambiguity&); |
| 56 |
Ambiguity(volatile Ambiguity&); |
| 57 |
}; |
| 58 |
|
| 59 |
struct 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 |
}; |
| 64 |
IsAmbiguous IAa; |
| 65 |
IsAmbiguous IAb(IAa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 66 |
|
| 67 |
struct Deleted { |
| 68 |
IsAmbiguous IA; // expected-note{{copy constructor of 'Deleted' is implicitly deleted because field 'IA' has a deleted copy constructor}} |
| 69 |
}; |
| 70 |
Deleted Da; |
| 71 |
Deleted 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. |
| 75 |
struct 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 |
| 82 |
struct AmbiguousCopyBase : Ambiguity { // expected-note 2{{copy constructor of 'AmbiguousCopyBase' is implicitly deleted because base class 'Ambiguity' has multiple copy constructors}} |
| 83 |
NonConst NC; |
| 84 |
}; |
| 85 |
extern AmbiguousCopyBase ACBa; |
| 86 |
AmbiguousCopyBase ACBb(ACBa); // expected-error {{deleted copy constructor}} |
| 87 |
|
| 88 |
struct DeletedCopyBase : AmbiguousCopyBase {}; // expected-note {{copy constructor of 'DeletedCopyBase' is implicitly deleted because base class 'AmbiguousCopyBase' has a deleted copy constructor}} |
| 89 |
extern DeletedCopyBase DCBa; |
| 90 |
DeletedCopyBase DCBb(DCBa); // expected-error {{deleted copy constructor}} |
| 91 |
|
| 92 |
struct InaccessibleCopyBase : NoAccess {}; // expected-note {{copy constructor of 'InaccessibleCopyBase' is implicitly deleted because base class 'NoAccess' has an inaccessible copy constructor}} |
| 93 |
extern InaccessibleCopyBase ICBa; |
| 94 |
InaccessibleCopyBase 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 |
| 98 |
struct NoAccessDtor { |
| 99 |
private: |
| 100 |
~NoAccessDtor(); |
| 101 |
friend struct HasAccessDtor; |
| 102 |
}; |
| 103 |
|
| 104 |
struct 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 |
}; |
| 109 |
HasNoAccessDtor HNADa; |
| 110 |
HasNoAccessDtor HNADb(HNADa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 111 |
|
| 112 |
struct HasAccessDtor { |
| 113 |
NoAccessDtor NAD; |
| 114 |
}; |
| 115 |
HasAccessDtor HADa; |
| 116 |
HasAccessDtor HADb(HADa); |
| 117 |
|
| 118 |
struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has an inaccessible destructor}} |
| 119 |
}; |
| 120 |
extern HasNoAccessDtorBase HNADBa; |
| 121 |
HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}} |
| 122 |
|
| 123 |
// -- a non-static data member of rvalue reference type |
| 124 |
int some_int; |
| 125 |
struct RValue { |
| 126 |
int && ri = static_cast<int&&>(some_int); // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}} |
| 127 |
}; |
| 128 |
RValue RVa; |
| 129 |
RValue RVb(RVa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 130 |
|
| 131 |
// FIXME: The error on the class-name is attached to the location of the |
| 132 |
// constructor. This is not especially clear. |
| 133 |
struct RValueTmp { // expected-error {{reference member 'ri' binds to a temporary}} |
| 134 |
int && ri = 1; // expected-note{{copy constructor of 'RValueTmp' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}} // expected-note {{default member init}} |
| 135 |
}; |
| 136 |
RValueTmp RVTa; // expected-note {{implicit default constructor for 'RValueTmp' first required here}} |
| 137 |
RValueTmp RVTb(RVTa); // expected-error{{call to implicitly-deleted copy constructor}} |
| 138 |
|
| 139 |
namespace PR13381 { |
| 140 |
struct S { |
| 141 |
S(const S&); |
| 142 |
S(const volatile S&) = delete; // expected-note{{deleted here}} |
| 143 |
}; |
| 144 |
struct T { |
| 145 |
volatile S s; // expected-note{{field 's' has a deleted copy constructor}} |
| 146 |
}; |
| 147 |
T &f(); |
| 148 |
T t = f(); // expected-error{{call to implicitly-deleted copy constructor}} |
| 149 |
} |
| 150 |
|
| 151 |
namespace Mutable { |
| 152 |
struct A { |
| 153 |
A(const A &); |
| 154 |
A(A &) = delete; // expected-note {{deleted here}} |
| 155 |
}; |
| 156 |
|
| 157 |
struct B { |
| 158 |
A a; |
| 159 |
B(const B &); |
| 160 |
}; |
| 161 |
B::B(const B &) = default; |
| 162 |
|
| 163 |
struct C { |
| 164 |
mutable A a; // expected-note {{deleted because field 'a' has a deleted copy constructor}} |
| 165 |
C(const C &); |
| 166 |
}; |
| 167 |
C::C(const C &) = default; // expected-error{{would delete}} |
| 168 |
} |