p6.cpp
5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --implicit-check-not='call{{.*}}dtor'
namespace std {
typedef decltype(sizeof(int)) size_t;
template <class E>
struct initializer_list {
const E *begin;
size_t size;
initializer_list() : begin(nullptr), size(0) {}
};
}
void then();
struct dtor {
~dtor();
};
dtor ctor();
auto &&lambda = [a = {ctor()}] {};
// CHECK-LABEL: define
// CHECK: call {{.*}}ctor
// CHECK: call {{.*}}atexit{{.*}}global_array_dtor
// CHECK-LABEL: define{{.*}}global_array_dtor
// CHECK: call {{.*}}dtor
// [lifetime extension occurs if the object was obtained by]
// -- a temporary materialization conversion
// CHECK-LABEL: ref_binding
void ref_binding() {
// CHECK: call {{.*}}ctor
auto &&x = ctor();
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// -- ( expression )
// CHECK-LABEL: parens
void parens() {
// CHECK: call {{.*}}ctor
auto &&x = ctor();
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// -- subscripting of an array
// CHECK-LABEL: array_subscript_1
void array_subscript_1() {
using T = dtor[1];
// CHECK: call {{.*}}ctor
auto &&x = T{ctor()}[0];
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: array_subscript_2
void array_subscript_2() {
using T = dtor[1];
// CHECK: call {{.*}}ctor
auto &&x = ((dtor*)T{ctor()})[0];
// CHECK: call {{.*}}dtor
// CHECK: call {{.*}}then
then();
// CHECK: }
}
struct with_member { dtor d; ~with_member(); };
struct with_ref_member { dtor &&d; ~with_ref_member(); };
// -- a class member access using the . operator [...]
// CHECK-LABEL: member_access_1
void member_access_1() {
// CHECK: call {{.*}}ctor
auto &&x = with_member{ctor()}.d;
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}with_member
// CHECK: }
}
// CHECK-LABEL: member_access_2
void member_access_2() {
// CHECK: call {{.*}}ctor
auto &&x = with_ref_member{ctor()}.d;
// CHECK: call {{.*}}with_ref_member
// CHECK: call {{.*}}dtor
// CHECK: call {{.*}}then
then();
// CHECK: }
}
// CHECK-LABEL: member_access_3
void member_access_3() {
// CHECK: call {{.*}}ctor
auto &&x = (&(const with_member&)with_member{ctor()})->d;
// CHECK: call {{.*}}with_member
// CHECK: call {{.*}}then
then();
// CHECK: }
}
// -- a pointer-to-member operation using the .* operator [...]
// CHECK-LABEL: member_ptr_access_1
void member_ptr_access_1() {
// CHECK: call {{.*}}ctor
auto &&x = with_member{ctor()}.*&with_member::d;
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}with_member
// CHECK: }
}
// CHECK-LABEL: member_ptr_access_2
void member_ptr_access_2() {
// CHECK: call {{.*}}ctor
auto &&x = (&(const with_member&)with_member{ctor()})->*&with_member::d;
// CHECK: call {{.*}}with_member
// CHECK: call {{.*}}then
then();
// CHECK: }
}
// -- a [named] cast [...]
// CHECK-LABEL: static_cast
void test_static_cast() {
// CHECK: call {{.*}}ctor
auto &&x = static_cast<dtor&&>(ctor());
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: const_cast
void test_const_cast() {
// CHECK: call {{.*}}ctor
auto &&x = const_cast<dtor&&>(ctor());
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: reinterpret_cast
void test_reinterpret_cast() {
// CHECK: call {{.*}}ctor
auto &&x = reinterpret_cast<dtor&&>(static_cast<dtor&&>(ctor()));
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: dynamic_cast
void test_dynamic_cast() {
// CHECK: call {{.*}}ctor
auto &&x = dynamic_cast<dtor&&>(ctor());
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// -- [explicit cast notation is defined in terms of the above]
// CHECK-LABEL: c_style_cast
void c_style_cast() {
// CHECK: call {{.*}}ctor
auto &&x = (dtor&&)ctor();
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: function_style_cast
void function_style_cast() {
// CHECK: call {{.*}}ctor
using R = dtor&&;
auto &&x = R(ctor());
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// -- a conditional operator
// CHECK-LABEL: conditional
void conditional(bool b) {
// CHECK: call {{.*}}ctor
// CHECK: call {{.*}}ctor
auto &&x = b ? (dtor&&)ctor() : (dtor&&)ctor();
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: call {{.*}}dtor
// CHECK: }
}
// -- a comma expression
// CHECK-LABEL: comma
void comma() {
// CHECK: call {{.*}}ctor
auto &&x = (true, (dtor&&)ctor());
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// This applies recursively: if an object is lifetime-extended and contains a
// reference, the referent is also extended.
// CHECK-LABEL: init_capture_ref
void init_capture_ref() {
// CHECK: call {{.*}}ctor
auto x = [&a = (const dtor&)ctor()] {};
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: init_capture_ref_indirect
void init_capture_ref_indirect() {
// CHECK: call {{.*}}ctor
auto x = [&a = (const dtor&)ctor()] {};
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}
// CHECK-LABEL: init_capture_init_list
void init_capture_init_list() {
// CHECK: call {{.*}}ctor
auto x = [a = {ctor()}] {};
// CHECK: call {{.*}}then
then();
// CHECK: call {{.*}}dtor
// CHECK: }
}