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