annotate clang/test/CXX/special/class.copy/p11.0x.copy.cpp @ 150:1d019706d866

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