blob: 0893ad6e28582dc34a5410017af4b29d73d580d8 [file] [log] [blame]
Artem Dergachev1f68d9d2018-02-15 03:13:36 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 -w %s > %t 2>&1
Artem Dergachev317291e2018-03-22 21:37:39 +00002// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11 %s
3// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++17 -w %s > %t 2>&1
4// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17 %s
Artem Dergachev41ffb302018-02-08 22:58:15 +00005
6class C {
7public:
8 C();
9 C(C *);
Artem Dergachev9ac2e112018-02-12 22:36:36 +000010 C(int, int);
Artem Dergachev5fc10332018-02-10 01:55:23 +000011
12 static C get();
Artem Dergachev1f68d9d2018-02-15 03:13:36 +000013 operator bool() const;
Artem Dergachev41ffb302018-02-08 22:58:15 +000014};
15
16typedef __typeof(sizeof(int)) size_t;
17void *operator new(size_t size, void *placement);
18
19namespace operator_new {
20
21// CHECK: void operatorNewWithConstructor()
22// CHECK: 1: CFGNewAllocator(C *)
23// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
24// CHECK-NEXT: 3: new C([B1.2])
25void operatorNewWithConstructor() {
26 new C();
27}
28
29// CHECK: void operatorNewWithConstructorWithOperatorNewWithContstructor()
30// CHECK: 1: CFGNewAllocator(C *)
31// CHECK-NEXT: 2: CFGNewAllocator(C *)
32// CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], class C)
33// CHECK-NEXT: 4: new C([B1.3])
34// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.6], class C)
35// CHECK-NEXT: 6: new C([B1.5])
36void operatorNewWithConstructorWithOperatorNewWithContstructor() {
37 new C(new C());
38}
39
40// CHECK: void operatorPlacementNewWithConstructorWithinPlacementArgument()
41// CHECK: 1: CFGNewAllocator(C *)
42// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
43// CHECK-NEXT: 3: new C([B1.2])
44// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
45// CHECK-NEXT: 5: CFGNewAllocator(C *)
46// CHECK-NEXT: 6: (CXXConstructExpr, [B1.7], class C)
47// CHECK-NEXT: 7: new ([B1.4]) C([B1.6])
48void operatorPlacementNewWithConstructorWithinPlacementArgument() {
49 new (new C()) C();
50}
51
52} // namespace operator_new
Artem Dergachev5fc10332018-02-10 01:55:23 +000053
54namespace decl_stmt {
55
56// CHECK: void simpleVariable()
57// CHECK: 1: (CXXConstructExpr, [B1.2], class C)
58// CHECK-NEXT: 2: C c;
59void simpleVariable() {
60 C c;
61}
62
63// CHECK: void simpleVariableWithBraces()
64// CHECK: 1: {} (CXXConstructExpr, [B1.2], class C)
65// CHECK-NEXT: 2: C c{};
66void simpleVariableWithBraces() {
67 C c{};
68}
69
70// CHECK: void simpleVariableWithConstructorArgument()
71// CHECK: 1: 0
72// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
73// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], class C)
74// CHECK-NEXT: 4: C c(0);
75void simpleVariableWithConstructorArgument() {
76 C c(0);
77}
78
79// CHECK: void simpleVariableWithOperatorNewInConstructorArgument()
80// CHECK: 1: CFGNewAllocator(C *)
81// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
82// CHECK-NEXT: 3: new C([B1.2])
83// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.5], class C)
84// CHECK-NEXT: 5: C c(new C());
85void simpleVariableWithOperatorNewInConstructorArgument() {
86 C c(new C());
87}
88
89// CHECK: void simpleVariableWithOperatorNewInBraces()
90// CHECK: 1: CFGNewAllocator(C *)
91// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
92// CHECK-NEXT: 3: new C([B1.2])
93// CHECK-NEXT: 4: {[B1.3]} (CXXConstructExpr, [B1.5], class C)
94// CHECK-NEXT: 5: C c{new C()};
95void simpleVariableWithOperatorNewInBraces() {
96 C c{new C()};
97}
98
Artem Dergachev5fc10332018-02-10 01:55:23 +000099// CHECK: void simpleVariableInitializedByValue()
100// CHECK: 1: C::get
101// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev1527dec2018-03-12 23:12:40 +0000102// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4])
Artem Dergachev317291e2018-03-22 21:37:39 +0000103// CXX11-NEXT: 4: [B1.3]
104// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.6], class C)
105// CXX11-NEXT: 6: C c = C::get();
106// CXX17-NEXT: 4: C c = C::get();
Artem Dergachev5fc10332018-02-10 01:55:23 +0000107void simpleVariableInitializedByValue() {
108 C c = C::get();
109}
110
Artem Dergachev9d3a7d82018-03-30 19:21:18 +0000111// FIXME: Find construction contexts for both branches in C++17.
112// Note that once it gets detected, the test for the get() branch would not
113// fail, because FileCheck allows partial matches.
Artem Dergachev08225bb2018-02-10 02:46:14 +0000114// CHECK: void simpleVariableWithTernaryOperator(bool coin)
115// CHECK: [B1]
Artem Dergachev317291e2018-03-22 21:37:39 +0000116// CXX11-NEXT: 1: [B4.2] ? [B2.5] : [B3.6]
117// CXX11-NEXT: 2: [B1.1]
118// CXX11-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], class C)
119// CXX11-NEXT: 4: C c = coin ? C::get() : C(0);
120// CXX17-NEXT: 1: [B4.2] ? [B2.3] : [B3.4]
121// CXX17-NEXT: 2: C c = coin ? C::get() : C(0);
Artem Dergachev08225bb2018-02-10 02:46:14 +0000122// CHECK: [B2]
123// CHECK-NEXT: 1: C::get
124// CHECK-NEXT: 2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev317291e2018-03-22 21:37:39 +0000125// CXX11-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4])
126// CXX11-NEXT: 4: [B2.3]
127// CXX11-NEXT: 5: [B2.4] (CXXConstructExpr, [B1.2], class C)
Artem Dergachev9d3a7d82018-03-30 19:21:18 +0000128// CXX17-NEXT: 3: [B2.2]()
Artem Dergachev08225bb2018-02-10 02:46:14 +0000129// CHECK: [B3]
130// CHECK-NEXT: 1: 0
131// CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, NullToPointer, class C *)
Artem Dergachev317291e2018-03-22 21:37:39 +0000132// CXX11-NEXT: 3: [B3.2] (CXXConstructExpr, [B3.5], class C)
133// CXX11-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
134// CXX11-NEXT: 5: [B3.4]
135// CXX11-NEXT: 6: [B3.5] (CXXConstructExpr, [B1.2], class C)
Artem Dergachev9d3a7d82018-03-30 19:21:18 +0000136// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, class C)
Artem Dergachev317291e2018-03-22 21:37:39 +0000137// CXX17-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
Artem Dergachev08225bb2018-02-10 02:46:14 +0000138// CHECK: [B4]
139// CHECK-NEXT: 1: coin
140// CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
141// CHECK-NEXT: T: [B4.2] ? ... : ...
142void simpleVariableWithTernaryOperator(bool coin) {
143 C c = coin ? C::get() : C(0);
144}
145
Artem Dergachevceb7d912018-02-24 02:05:11 +0000146// CHECK: void simpleVariableWithElidableCopy()
147// CHECK: 1: 0
148// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
149// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.5], class C)
150// CHECK-NEXT: 4: C([B1.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
Artem Dergachev317291e2018-03-22 21:37:39 +0000151// CXX11-NEXT: 5: [B1.4]
152// CXX11-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.7], class C)
153// CXX11-NEXT: 7: C c = C(0);
154// CXX17-NEXT: 5: C c = C(0);
Artem Dergachevceb7d912018-02-24 02:05:11 +0000155void simpleVariableWithElidableCopy() {
156 C c = C(0);
157}
158
Artem Dergachev5fc10332018-02-10 01:55:23 +0000159// CHECK: void referenceVariableWithConstructor()
160// CHECK: 1: 0
161// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
Artem Dergachevf43ac4c2018-02-24 02:00:30 +0000162// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], const class C)
Artem Dergachev5fc10332018-02-10 01:55:23 +0000163// CHECK-NEXT: 4: [B1.3]
164// CHECK-NEXT: 5: const C &c(0);
165void referenceVariableWithConstructor() {
166 const C &c(0);
167}
168
Artem Dergachev5fc10332018-02-10 01:55:23 +0000169// CHECK: void referenceVariableWithInitializer()
Artem Dergachev8cc55e92018-02-24 02:07:50 +0000170// CHECK: 1: C() (CXXConstructExpr, [B1.3], class C)
Artem Dergachev5fc10332018-02-10 01:55:23 +0000171// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class C)
172// CHECK-NEXT: 3: [B1.2]
173// CHECK-NEXT: 4: const C &c = C();
174void referenceVariableWithInitializer() {
175 const C &c = C();
176}
177
Artem Dergachev08225bb2018-02-10 02:46:14 +0000178// CHECK: void referenceVariableWithTernaryOperator(bool coin)
179// CHECK: [B1]
Artem Dergachev317291e2018-03-22 21:37:39 +0000180// CXX11-NEXT: 1: [B4.2] ? [B2.5] : [B3.6]
181// CXX17-NEXT: 1: [B4.2] ? [B2.3] : [B3.4]
Artem Dergachev08225bb2018-02-10 02:46:14 +0000182// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class C)
183// CHECK-NEXT: 3: [B1.2]
184// CHECK-NEXT: 4: const C &c = coin ? C::get() : C(0);
185// CHECK: [B2]
186// CHECK-NEXT: 1: C::get
187// CHECK-NEXT: 2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev317291e2018-03-22 21:37:39 +0000188// CXX11-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4])
189// CXX11-NEXT: 4: [B2.3]
190// CXX11-NEXT: 5: [B2.4] (CXXConstructExpr, [B1.3], class C)
191// CXX17-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B1.3])
Artem Dergachev08225bb2018-02-10 02:46:14 +0000192// CHECK: [B3]
193// CHECK-NEXT: 1: 0
194// CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, NullToPointer, class C *)
Artem Dergachev317291e2018-03-22 21:37:39 +0000195// CXX11-NEXT: 3: [B3.2] (CXXConstructExpr, [B3.5], class C)
196// CXX11-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
197// CXX11-NEXT: 5: [B3.4]
198// CXX11-NEXT: 6: [B3.5] (CXXConstructExpr, [B1.3], class C)
199// CXX17-NEXT: 3: [B3.2] (CXXConstructExpr, [B1.3], class C)
200// CXX17-NEXT: 4: C([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
Artem Dergachev08225bb2018-02-10 02:46:14 +0000201// CHECK: [B4]
202// CHECK-NEXT: 1: coin
203// CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
204// CHECK-NEXT: T: [B4.2] ? ... : ...
205void referenceVariableWithTernaryOperator(bool coin) {
206 const C &c = coin ? C::get() : C(0);
207}
208
Artem Dergachev5fc10332018-02-10 01:55:23 +0000209} // end namespace decl_stmt
Artem Dergachev5a281bb2018-02-10 02:18:04 +0000210
211namespace ctor_initializers {
212
213class D: public C {
214 C c1;
215
216public:
217
218// CHECK: D()
219// CHECK: 1: (CXXConstructExpr, C() (Base initializer), class C)
220// CHECK-NEXT: 2: C([B1.1]) (Base initializer)
221// CHECK-NEXT: 3: CFGNewAllocator(C *)
222// CHECK-NEXT: 4: (CXXConstructExpr, [B1.5], class C)
223// CHECK-NEXT: 5: new C([B1.4])
224// CHECK-NEXT: 6: [B1.5] (CXXConstructExpr, c1([B1.5]) (Member initializer), class C)
225// CHECK-NEXT: 7: c1([B1.6]) (Member initializer)
226 D(): C(), c1(new C()) {}
227
228// CHECK: D(int)
229// CHECK: 1: (CXXConstructExpr, D() (Delegating initializer), class ctor_initializers::D)
230// CHECK-NEXT: 2: D([B1.1]) (Delegating initializer)
231 D(int): D() {}
Artem Dergachev08225bb2018-02-10 02:46:14 +0000232
Artem Dergachev317291e2018-03-22 21:37:39 +0000233// FIXME: Why is CXXRecordTypedCall not present in C++17? Note that once it gets
234// detected the test would not fail, because FileCheck allows partial matches.
Artem Dergachev08225bb2018-02-10 02:46:14 +0000235// CHECK: D(double)
236// CHECK: 1: C::get
237// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev1527dec2018-03-12 23:12:40 +0000238// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4])
Artem Dergachev08225bb2018-02-10 02:46:14 +0000239// CHECK-NEXT: 4: [B1.3]
240// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, C([B1.4]) (Base initializer), class C)
241// CHECK-NEXT: 6: C([B1.5]) (Base initializer)
242// CHECK-NEXT: 7: CFGNewAllocator(C *)
243// CHECK-NEXT: 8: C::get
244// CHECK-NEXT: 9: [B1.8] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev317291e2018-03-22 21:37:39 +0000245// CXX11-NEXT: 10: [B1.9]() (CXXRecordTypedCall, [B1.11])
246// CXX11-NEXT: 11: [B1.10]
247// CXX11-NEXT: 12: [B1.11] (CXXConstructExpr, [B1.13], class C)
248// CXX11-NEXT: 13: new C([B1.12])
249// CXX11-NEXT: 14: [B1.13] (CXXConstructExpr, c1([B1.13]) (Member initializer), class C)
250// CXX11-NEXT: 15: c1([B1.14]) (Member initializer)
251// CXX17-NEXT: 10: [B1.9]()
252// CXX17-NEXT: 11: new C([B1.10])
253// CXX17-NEXT: 12: [B1.11] (CXXConstructExpr, c1([B1.11]) (Member initializer), class C)
254// CXX17-NEXT: 13: c1([B1.12]) (Member initializer)
Artem Dergachev08225bb2018-02-10 02:46:14 +0000255 D(double): C(C::get()), c1(new C(C::get())) {}
Artem Dergachev5a281bb2018-02-10 02:18:04 +0000256};
257
Artem Dergachev922455f2018-03-22 22:02:38 +0000258// Let's see if initializers work well for fields with destructors.
259class E {
260public:
261 static E get();
262 ~E();
263};
264
265class F {
266 E e;
267
268public:
269// FIXME: There should be no temporary destructor in C++17.
270// CHECK: F()
271// CHECK: 1: E::get
272// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class ctor_initializers::E (*)(
273// CXX11-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
274// CXX11-NEXT: 4: [B1.3] (BindTemporary)
275// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class ctor_initializers::E)
276// CXX11-NEXT: 6: [B1.5]
277// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, e([B1.6]) (Member initializer), class ctor_initializers
278// CXX11-NEXT: 8: e([B1.7]) (Member initializer)
279// CXX11-NEXT: 9: ~ctor_initializers::E() (Temporary object destructor)
280// CXX17-NEXT: 3: [B1.2]() (CXXRecordTypedCall, e([B1.4]) (Member initializer), [B1.4])
281// CXX17-NEXT: 4: [B1.3] (BindTemporary)
282// CXX17-NEXT: 5: e([B1.4]) (Member initializer)
283// CXX17-NEXT: 6: ~ctor_initializers::E() (Temporary object destructor)
284 F(): e(E::get()) {}
285};
Artem Dergachev5a281bb2018-02-10 02:18:04 +0000286} // end namespace ctor_initializers
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000287
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000288namespace return_stmt_without_dtor {
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000289
290// CHECK: C returnVariable()
291// CHECK: 1: (CXXConstructExpr, [B1.2], class C)
292// CHECK-NEXT: 2: C c;
293// CHECK-NEXT: 3: c
294// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, class C)
295// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.6], class C)
296// CHECK-NEXT: 6: return [B1.5];
297C returnVariable() {
298 C c;
299 return c;
300}
301
302// CHECK: C returnEmptyBraces()
303// CHECK: 1: {} (CXXConstructExpr, [B1.2], class C)
304// CHECK-NEXT: 2: return [B1.1];
305C returnEmptyBraces() {
306 return {};
307}
308
309// CHECK: C returnBracesWithOperatorNew()
310// CHECK: 1: CFGNewAllocator(C *)
311// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
312// CHECK-NEXT: 3: new C([B1.2])
313// CHECK-NEXT: 4: {[B1.3]} (CXXConstructExpr, [B1.5], class C)
314// CHECK-NEXT: 5: return [B1.4];
315C returnBracesWithOperatorNew() {
316 return {new C()};
317}
318
319// CHECK: C returnBracesWithMultipleItems()
320// CHECK: 1: 123
321// CHECK-NEXT: 2: 456
322// CHECK-NEXT: 3: {[B1.1], [B1.2]} (CXXConstructExpr, [B1.4], class C)
323// CHECK-NEXT: 4: return [B1.3];
324C returnBracesWithMultipleItems() {
325 return {123, 456};
326}
327
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000328// CHECK: C returnTemporary()
Artem Dergachevf43ac4c2018-02-24 02:00:30 +0000329// CHECK: 1: C() (CXXConstructExpr, [B1.2], class C)
Artem Dergachev317291e2018-03-22 21:37:39 +0000330// CXX11-NEXT: 2: [B1.1]
331// CXX11-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], class C)
332// CXX11-NEXT: 4: return [B1.3];
333// CXX17-NEXT: 2: return [B1.1];
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000334C returnTemporary() {
335 return C();
336}
337
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000338// CHECK: C returnTemporaryWithArgument()
339// CHECK: 1: nullptr
340// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
Artem Dergachevceb7d912018-02-24 02:05:11 +0000341// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.5], class C)
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000342// CHECK-NEXT: 4: C([B1.3]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
Artem Dergachev317291e2018-03-22 21:37:39 +0000343// CXX11-NEXT: 5: [B1.4]
344// CXX11-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.7], class C)
345// CXX11-NEXT: 7: return [B1.6];
346// CXX17-NEXT: 5: return [B1.4];
347
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000348C returnTemporaryWithArgument() {
349 return C(nullptr);
350}
351
352// CHECK: C returnTemporaryConstructedByFunction()
353// CHECK: 1: C::get
354// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev1527dec2018-03-12 23:12:40 +0000355// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4])
Artem Dergachev317291e2018-03-22 21:37:39 +0000356// CXX11-NEXT: 4: [B1.3]
357// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.6], class C)
358// CXX11-NEXT: 6: return [B1.5];
359// CXX17-NEXT: 4: return [B1.3];
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000360C returnTemporaryConstructedByFunction() {
361 return C::get();
362}
363
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000364// CHECK: C returnChainOfCopies()
365// CHECK: 1: C::get
366// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
Artem Dergachev317291e2018-03-22 21:37:39 +0000367// CXX11-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4])
368// CXX11-NEXT: 4: [B1.3]
369// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.7], class C)
370// CXX11-NEXT: 6: C([B1.5]) (CXXFunctionalCastExpr, ConstructorConversion, class C)
371// CXX11-NEXT: 7: [B1.6]
372// CXX11-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.9], class C)
373// CXX11-NEXT: 9: return [B1.8];
374// CXX17-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5])
375// CXX17-NEXT: 4: C([B1.3]) (CXXFunctionalCastExpr, NoOp, class C)
376// CXX17-NEXT: 5: return [B1.4];
Artem Dergachev9ac2e112018-02-12 22:36:36 +0000377C returnChainOfCopies() {
378 return C(C::get());
379}
380
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000381} // end namespace return_stmt_without_dtor
382
383namespace return_stmt_with_dtor {
384
385class D {
386public:
387 D();
388 ~D();
389};
390
Artem Dergachev317291e2018-03-22 21:37:39 +0000391// FIXME: There should be no temporary destructor in C++17.
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000392// CHECK: return_stmt_with_dtor::D returnTemporary()
Artem Dergachev317291e2018-03-22 21:37:39 +0000393// CXX11: 1: return_stmt_with_dtor::D() (CXXConstructExpr, [B1.2], [B1.4], class return_stmt_with_dtor::D)
394// CXX11-NEXT: 2: [B1.1] (BindTemporary)
395// CXX11-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class return_stmt_with_dtor::D)
396// CXX11-NEXT: 4: [B1.3]
397// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.7], class return_stmt_with_dtor::D)
398// CXX11-NEXT: 6: ~return_stmt_with_dtor::D() (Temporary object destructor)
399// CXX11-NEXT: 7: return [B1.5];
400// CXX17: 1: return_stmt_with_dtor::D() (CXXConstructExpr, [B1.4], [B1.2], class return_stmt_w
401// CXX17-NEXT: 2: [B1.1] (BindTemporary)
402// CXX17-NEXT: 3: ~return_stmt_with_dtor::D() (Temporary object destructor)
403// CXX17-NEXT: 4: return [B1.2];
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000404D returnTemporary() {
405 return D();
406}
407
Artem Dergachev317291e2018-03-22 21:37:39 +0000408// FIXME: There should be no temporary destructor in C++17.
409// CHECK: void returnByValueIntoVariable()
410// CHECK: 1: returnTemporary
411// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class return_stmt_with_dtor::D (*)(void))
412// CXX11-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
413// CXX11-NEXT: 4: [B1.3] (BindTemporary)
414// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class return_stmt_with_dtor::D)
415// CXX11-NEXT: 6: [B1.5]
416// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, [B1.8], class return_stmt_with_dtor::D)
417// CXX11-NEXT: 8: return_stmt_with_dtor::D d = returnTemporary();
418// CXX11-NEXT: 9: ~return_stmt_with_dtor::D() (Temporary object destructor)
419// CXX11-NEXT: 10: [B1.8].~D() (Implicit destructor)
420// CXX17-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5], [B1.4])
421// CXX17-NEXT: 4: [B1.3] (BindTemporary)
422// CXX17-NEXT: 5: return_stmt_with_dtor::D d = returnTemporary();
423// CXX17-NEXT: 6: ~return_stmt_with_dtor::D() (Temporary object destructor)
424// CXX17-NEXT: 7: [B1.5].~D() (Implicit destructor)
425void returnByValueIntoVariable() {
426 D d = returnTemporary();
427}
428
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000429} // end namespace return_stmt_with_dtor
430
431namespace temporary_object_expr_without_dtors {
432
433// TODO: Should provide construction context for the constructor,
434// even if there is no specific trigger statement here.
435// CHECK: void simpleTemporary()
436// CHECK 1: C() (CXXConstructExpr, class C)
437void simpleTemporary() {
438 C();
439}
440
441// TODO: Should provide construction context for the constructor,
442// CHECK: void temporaryInCondition()
443// CHECK: 1: C() (CXXConstructExpr, class C)
444// CHECK-NEXT: 2: [B2.1] (ImplicitCastExpr, NoOp, const class C)
445// CHECK-NEXT: 3: [B2.2].operator bool
446// CHECK-NEXT: 4: [B2.2]
447// CHECK-NEXT: 5: [B2.4] (ImplicitCastExpr, UserDefinedConversion, _Bool)
448// CHECK-NEXT: T: if [B2.5]
449void temporaryInCondition() {
450 if (C());
451}
452
Artem Dergachevab9b78b2018-04-19 23:30:15 +0000453// CHECK: void temporaryInConditionVariable()
454// CHECK: 1: C() (CXXConstructExpr, [B2.2], class C)
455// CXX11-NEXT: 2: [B2.1]
456// CXX11-NEXT: 3: [B2.2] (CXXConstructExpr, [B2.4], class C)
457// CXX11-NEXT: 4: C c = C();
458// CXX11-NEXT: 5: c
459// CXX11-NEXT: 6: [B2.5] (ImplicitCastExpr, NoOp, const class C)
460// CXX11-NEXT: 7: [B2.6].operator bool
461// CXX11-NEXT: 8: [B2.6]
462// CXX11-NEXT: 9: [B2.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
463// CXX11-NEXT: T: if [B2.9]
464// CXX17-NEXT: 2: C c = C();
465// CXX17-NEXT: 3: c
466// CXX17-NEXT: 4: [B2.3] (ImplicitCastExpr, NoOp, const class C)
467// CXX17-NEXT: 5: [B2.4].operator bool
468// CXX17-NEXT: 6: [B2.4]
469// CXX17-NEXT: 7: [B2.6] (ImplicitCastExpr, UserDefinedConversion, _Bool)
470// CXX17-NEXT: T: if [B2.7]
471void temporaryInConditionVariable() {
472 if (C c = C());
473}
474
475
476// CHECK: void temporaryInForLoopConditionVariable()
477// CHECK: [B2]
478// CXX11-NEXT: 1: C() (CXXConstructExpr, [B2.2], class C)
479// CXX11-NEXT: 2: [B2.1]
480// CXX11-NEXT: 3: [B2.2] (CXXConstructExpr, [B2.4], class C)
481// CXX11-NEXT: 4: C c2 = C();
482// CXX11-NEXT: 5: c2
483// CXX11-NEXT: 6: [B2.5] (ImplicitCastExpr, NoOp, const class C)
484// CXX11-NEXT: 7: [B2.6].operator bool
485// CXX11-NEXT: 8: [B2.6]
486// CXX11-NEXT: 9: [B2.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
487// CXX11-NEXT: T: for (...; [B2.9]; )
488// CXX17-NEXT: 1: C() (CXXConstructExpr, [B2.2], class C)
489// CXX17-NEXT: 2: C c2 = C();
490// CXX17-NEXT: 3: c2
491// CXX17-NEXT: 4: [B2.3] (ImplicitCastExpr, NoOp, const class C)
492// CXX17-NEXT: 5: [B2.4].operator bool
493// CXX17-NEXT: 6: [B2.4]
494// CXX17-NEXT: 7: [B2.6] (ImplicitCastExpr, UserDefinedConversion, _Bool)
495// CXX17-NEXT: T: for (...; [B2.7]; )
496// CHECK: [B3]
497// CXX11-NEXT: 1: C() (CXXConstructExpr, [B3.2], class C)
498// CXX11-NEXT: 2: [B3.1]
499// CXX11-NEXT: 3: [B3.2] (CXXConstructExpr, [B3.4], class C)
500// CXX11-NEXT: 4: C c1 = C();
501// CXX17-NEXT: 1: C() (CXXConstructExpr, [B3.2], class C)
502// CXX17-NEXT: 2: C c1 = C();
503void temporaryInForLoopConditionVariable() {
504 for (C c1 = C(); C c2 = C(); );
505}
506
507
508// FIXME: Find construction context for the loop condition variable.
509// CHECK: void temporaryInWhileLoopConditionVariable()
510// CXX11: 1: C() (CXXConstructExpr, [B2.2], class C)
511// CXX11-NEXT: 2: [B2.1]
512// CXX11-NEXT: 3: [B2.2] (CXXConstructExpr, [B2.4], class C)
513// CXX11-NEXT: 4: C c = C();
514// CXX11-NEXT: 5: c
515// CXX11-NEXT: 6: [B2.5] (ImplicitCastExpr, NoOp, const class C)
516// CXX11-NEXT: 7: [B2.6].operator bool
517// CXX11-NEXT: 8: [B2.6]
518// CXX11-NEXT: 9: [B2.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
519// CXX11-NEXT: T: while [B2.9]
520// CXX17: 1: C() (CXXConstructExpr, [B2.2], class C)
521// CXX17-NEXT: 2: C c = C();
522// CXX17-NEXT: 3: c
523// CXX17-NEXT: 4: [B2.3] (ImplicitCastExpr, NoOp, const class C)
524// CXX17-NEXT: 5: [B2.4].operator bool
525// CXX17-NEXT: 6: [B2.4]
526// CXX17-NEXT: 7: [B2.6] (ImplicitCastExpr, UserDefinedConversion, _Bool)
527// CXX17-NEXT: T: while [B2.7]
528void temporaryInWhileLoopConditionVariable() {
529 while (C c = C());
530}
531
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000532} // end namespace temporary_object_expr_without_dtors
533
534namespace temporary_object_expr_with_dtors {
535
536class D {
537public:
538 D();
539 D(int);
540 ~D();
541
542 static D get();
543
544 operator bool() const;
545};
546
547// CHECK: void simpleTemporary()
548// CHECK: 1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B1.2], class temporary_object_expr_with_dtors::D)
549// CHECK-NEXT: 2: [B1.1] (BindTemporary)
550// CHECK-NEXT: 3: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
551void simpleTemporary() {
552 D();
553}
554
555// CHECK: void temporaryInCondition()
556// CHECK: 1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B2.2], class temporary_object_expr_with_dtors::D)
557// CHECK-NEXT: 2: [B2.1] (BindTemporary)
558// CHECK-NEXT: 3: [B2.2] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
559// CHECK-NEXT: 4: [B2.3].operator bool
560// CHECK-NEXT: 5: [B2.3]
561// CHECK-NEXT: 6: [B2.5] (ImplicitCastExpr, UserDefinedConversion, _Bool)
562// CHECK-NEXT: 7: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
563// CHECK-NEXT: T: if [B2.6]
564void temporaryInCondition() {
565 if (D());
566}
567
568// CHECK: void referenceVariableWithConstructor()
569// CHECK: 1: 0
Artem Dergachevf43ac4c2018-02-24 02:00:30 +0000570// CHECK-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], [B1.4], const class temporary_object_expr_with_dtors::D)
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000571// CHECK-NEXT: 3: [B1.2] (BindTemporary)
572// CHECK-NEXT: 4: [B1.3]
573// CHECK-NEXT: 5: const temporary_object_expr_with_dtors::D &d(0);
574// CHECK-NEXT: 6: [B1.5].~D() (Implicit destructor)
575void referenceVariableWithConstructor() {
576 const D &d(0);
577}
578
579// CHECK: void referenceVariableWithInitializer()
Artem Dergachev8cc55e92018-02-24 02:07:50 +0000580// CHECK: 1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B1.2], [B1.4], class temporary_object_expr_with_dtors::D)
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000581// CHECK-NEXT: 2: [B1.1] (BindTemporary)
582// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
583// CHECK-NEXT: 4: [B1.3]
584// CHECK-NEXT: 5: const temporary_object_expr_with_dtors::D &d = temporary_object_expr_with_dtors::D();
585// CHECK-NEXT: 6: [B1.5].~D() (Implicit destructor)
586void referenceVariableWithInitializer() {
587 const D &d = D();
588}
589
590// CHECK: void referenceVariableWithTernaryOperator(bool coin)
Artem Dergachev317291e2018-03-22 21:37:39 +0000591// CXX11: [B1]
592// CXX11-NEXT: 1: [B4.4].~D() (Implicit destructor)
593// CXX11: [B2]
594// CXX11-NEXT: 1: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
595// CXX11: [B3]
596// CXX11-NEXT: 1: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
597// CXX11: [B4]
598// CXX11-NEXT: 1: [B7.2] ? [B5.8] : [B6.8]
599// CXX11-NEXT: 2: [B4.1] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
600// CXX11-NEXT: 3: [B4.2]
601// CXX11-NEXT: 4: const temporary_object_expr_with_dtors::D &d = coin ? D::get() : temporary_object_expr_with_dtors::D(0);
602// CXX11-NEXT: T: (Temp Dtor) [B6.3]
603// CXX11: [B5]
604// CXX11-NEXT: 1: D::get
605// CXX11-NEXT: 2: [B5.1] (ImplicitCastExpr, FunctionToPointerDecay, class temporary_object_expr_with_dtors::D (*)(void))
606// CXX11-NEXT: 3: [B5.2]() (CXXRecordTypedCall, [B5.4], [B5.6])
607// CXX11-NEXT: 4: [B5.3] (BindTemporary)
608// CXX11-NEXT: 5: [B5.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
609// CXX11-NEXT: 6: [B5.5]
610// CXX11-NEXT: 7: [B5.6] (CXXConstructExpr, [B5.8], [B4.3], class temporary_object_expr_with_dtors::D)
611// CXX11-NEXT: 8: [B5.7] (BindTemporary)
612// CXX11: [B6]
613// CXX11-NEXT: 1: 0
614// CXX11-NEXT: 2: [B6.1] (CXXConstructExpr, [B6.3], [B6.6], class temporary_object_expr_with_dtors::D)
615// CXX11-NEXT: 3: [B6.2] (BindTemporary)
616// CXX11-NEXT: 4: temporary_object_expr_with_dtors::D([B6.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
617// CXX11-NEXT: 5: [B6.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
618// CXX11-NEXT: 6: [B6.5]
619// CXX11-NEXT: 7: [B6.6] (CXXConstructExpr, [B6.8], [B4.3], class temporary_object_expr_with_dtors::D)
620// CXX11-NEXT: 8: [B6.7] (BindTemporary)
621// CXX11: [B7]
622// CXX11-NEXT: 1: coin
623// CXX11-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
624// CXX11-NEXT: T: [B7.2] ? ... : ...
625// CXX17: [B1]
626// CXX17-NEXT: 1: [B4.2] ? [B2.4] : [B3.4]
627// CXX17-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
628// CXX17-NEXT: 3: [B1.2]
629// CXX17-NEXT: 4: const temporary_object_expr_with_dtors::D &d = coin ? D::get() : temporary_object_expr_with_dtors::D(0);
630// CXX17-NEXT: 5: [B1.4].~D() (Implicit destructor)
631// CXX17: [B2]
632// CXX17-NEXT: 1: D::get
633// CXX17-NEXT: 2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, class temporary_object_expr_with_dtors::D (*)(void))
634// CXX17-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4], [B1.3])
635// CXX17-NEXT: 4: [B2.3] (BindTemporary)
636// CXX17: [B3]
637// CXX17-NEXT: 1: 0
638// CXX17-NEXT: 2: [B3.1] (CXXConstructExpr, [B3.3], [B1.3], class temporary_object_expr_with_dtors::D)
639// CXX17-NEXT: 3: [B3.2] (BindTemporary)
640// CXX17-NEXT: 4: temporary_object_expr_with_dtors::D([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
641// CXX17: [B4]
642// CXX17-NEXT: 1: coin
643// CXX17-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
644// CXX17-NEXT: T: [B4.2] ? ... : ...
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000645void referenceVariableWithTernaryOperator(bool coin) {
646 const D &d = coin ? D::get() : D(0);
647}
Artem Dergachevceb7d912018-02-24 02:05:11 +0000648
649// CHECK: void referenceWithFunctionalCast()
650// CHECK: 1: 1
651// CHECK-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], [B1.5], class temporary_object_expr_with_dtors::D)
652// CHECK-NEXT: 3: [B1.2] (BindTemporary)
653// CHECK-NEXT: 4: temporary_object_expr_with_dtors::D([B1.3]) (CXXFunctionalCastExpr, ConstructorCon
654// CHECK-NEXT: 5: [B1.4]
655// CHECK-NEXT: 6: temporary_object_expr_with_dtors::D &&d = temporary_object_expr_with_dtors::D(1);
656// CHECK-NEXT: 7: [B1.6].~D() (Implicit destructor)
657void referenceWithFunctionalCast() {
658 D &&d = D(1);
659}
Artem Dergacheva6d91d52018-02-24 03:10:15 +0000660
661// Test the condition constructor, we don't care about branch constructors here.
662// CHECK: void constructorInTernaryCondition()
Artem Dergachev317291e2018-03-22 21:37:39 +0000663// CXX11: 1: 1
664// CXX11-NEXT: 2: [B7.1] (CXXConstructExpr, [B7.3], class temporary_object_expr_with_dtors::D)
665// CXX11-NEXT: 3: [B7.2] (BindTemporary)
666// CXX11-NEXT: 4: temporary_object_expr_with_dtors::D([B7.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
667// CXX11-NEXT: 5: [B7.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
668// CXX11-NEXT: 6: [B7.5].operator bool
669// CXX11-NEXT: 7: [B7.5]
670// CXX11-NEXT: 8: [B7.7] (ImplicitCastExpr, UserDefinedConversion, _Bool)
671// CXX11-NEXT: T: [B7.8] ? ... : ...
672// CXX17: 1: 1
673// CXX17-NEXT: 2: [B4.1] (CXXConstructExpr, [B4.3], class temporary_object_expr_with_dtors::D)
674// CXX17-NEXT: 3: [B4.2] (BindTemporary)
675// CXX17-NEXT: 4: temporary_object_expr_with_dtors::D([B4.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
676// CXX17-NEXT: 5: [B4.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
677// CXX17-NEXT: 6: [B4.5].operator bool
678// CXX17-NEXT: 7: [B4.5]
679// CXX17-NEXT: 8: [B4.7] (ImplicitCastExpr, UserDefinedConversion, _Bool)
680// CXX17-NEXT: T: [B4.8] ? ... : ...
Artem Dergacheva6d91d52018-02-24 03:10:15 +0000681void constructorInTernaryCondition() {
682 const D &d = D(1) ? D(2) : D(3);
683}
Artem Dergachev66030522018-03-01 01:09:24 +0000684
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000685} // end namespace temporary_object_expr_with_dtors
Artem Dergachev66030522018-03-01 01:09:24 +0000686
687namespace implicit_constructor_conversion {
688
689class A {};
690A get();
691
692class B {
693public:
694 B(const A &);
695 ~B() {}
696};
697
Artem Dergachev13f96642018-03-09 01:39:59 +0000698// CHECK: void implicitConstructionConversionFromTemporary()
699// CHECK: 1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
Artem Dergachev317291e2018-03-22 21:37:39 +0000700// CXX11-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
701// CXX11-NEXT: 3: [B1.2]
702// CXX11-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], [B1.8], class implicit_constructor_conversion::B)
703// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
704// CXX11-NEXT: 6: [B1.5] (BindTemporary)
705// CXX11-NEXT: 7: [B1.6] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
706// CXX11-NEXT: 8: [B1.7]
707// CXX11-NEXT: 9: [B1.8] (CXXConstructExpr, [B1.10], class implicit_constructor_conversion::B)
708// CXX11-NEXT: 10: implicit_constructor_conversion::B b = implicit_constructor_conversion::A();
709// CXX11-NEXT: 11: ~implicit_constructor_conversion::B() (Temporary object destructor)
710// CXX11-NEXT: 12: [B1.10].~B() (Implicit destructor)
711// CXX17-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
712// CXX17-NEXT: 3: [B1.2]
713// CXX17-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], class implicit_constructor_conversion::B)
714// CXX17-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
715// CXX17-NEXT: 6: implicit_constructor_conversion::B b = implicit_constructor_conversion::A();
716// CXX17-NEXT: 7: [B1.6].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000717void implicitConstructionConversionFromTemporary() {
718 B b = A();
719}
720
Artem Dergachev66030522018-03-01 01:09:24 +0000721// CHECK: void implicitConstructionConversionFromFunctionValue()
722// CHECK: 1: get
Artem Dergachev13f96642018-03-09 01:39:59 +0000723// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class implicit_constructor_conversion::A (*)(void))
Artem Dergachev1527dec2018-03-12 23:12:40 +0000724// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5])
Artem Dergachev13f96642018-03-09 01:39:59 +0000725// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
726// CHECK-NEXT: 5: [B1.4]
Artem Dergachev317291e2018-03-22 21:37:39 +0000727// CXX11-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], [B1.10], class implicit_constructor_conversion::B)
728// CXX11-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
729// CXX11-NEXT: 8: [B1.7] (BindTemporary)
730// CXX11-NEXT: 9: [B1.8] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
731// CXX11-NEXT: 10: [B1.9]
732// CXX11-NEXT: 11: [B1.10] (CXXConstructExpr, [B1.12], class implicit_constructor_conversion::B)
733// CXX11-NEXT: 12: implicit_constructor_conversion::B b = get();
734// CXX11-NEXT: 13: ~implicit_constructor_conversion::B() (Temporary object destructor)
735// CXX11-NEXT: 14: [B1.12].~B() (Implicit destructor)
736// CXX17-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], class implicit_constructor_conversion::B)
737// CXX17-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
738// CXX17-NEXT: 8: implicit_constructor_conversion::B b = get();
739// CXX17-NEXT: 9: [B1.8].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000740void implicitConstructionConversionFromFunctionValue() {
741 B b = get();
742}
743
744// CHECK: void implicitConstructionConversionFromTemporaryWithLifetimeExtension()
745// CHECK: 1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
746// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
747// CHECK-NEXT: 3: [B1.2]
748// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.7], class implicit_constructor_conversion::B)
749// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
750// CHECK-NEXT: 6: [B1.5] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
751// CHECK-NEXT: 7: [B1.6]
752// CHECK-NEXT: 8: const implicit_constructor_conversion::B &b = implicit_constructor_conversion::A();
753// CHECK-NEXT: 9: [B1.8].~B() (Implicit destructor)
754void implicitConstructionConversionFromTemporaryWithLifetimeExtension() {
755 const B &b = A();
756}
757
Artem Dergachev13f96642018-03-09 01:39:59 +0000758// CHECK: void implicitConstructionConversionFromFunctionValueWithLifetimeExtension()
759// CHECK: 1: get
Artem Dergachev66030522018-03-01 01:09:24 +0000760// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class implicit_constructor_conver
Artem Dergachev1527dec2018-03-12 23:12:40 +0000761// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5])
Artem Dergachev66030522018-03-01 01:09:24 +0000762// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
763// CHECK-NEXT: 5: [B1.4]
Artem Dergachev13f96642018-03-09 01:39:59 +0000764// CHECK-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.9], class implicit_constructor_conversion::B)
Artem Dergachev66030522018-03-01 01:09:24 +0000765// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_convers
766// CHECK-NEXT: 8: [B1.7] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
767// CHECK-NEXT: 9: [B1.8]
768// CHECK-NEXT: 10: const implicit_constructor_conversion::B &b = get();
769// CHECK-NEXT: 11: [B1.10].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000770void implicitConstructionConversionFromFunctionValueWithLifetimeExtension() {
Artem Dergachev66030522018-03-01 01:09:24 +0000771 const B &b = get(); // no-crash
772}
773
774} // end namespace implicit_constructor_conversion
Artem Dergachev72da02f2018-04-19 23:09:22 +0000775
776namespace argument_constructors {
777class D {
778public:
779 D();
780 ~D();
781};
782
783void useC(C c);
784void useCByReference(const C &c);
785void useD(D d);
786void useDByReference(const D &d);
787
788// FIXME: Find construction context for the argument.
789// CHECK: void passArgument()
790// CHECK: 1: useC
791// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(class C))
792// CXX11-NEXT: 3: C() (CXXConstructExpr, [B1.4], class C)
793// CXX11-NEXT: 4: [B1.3]
794// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, class C)
795// CXX11-NEXT: 6: [B1.2]([B1.5])
796// CXX17-NEXT: 3: C() (CXXConstructExpr, class C)
797// CXX17-NEXT: 4: [B1.2]([B1.3])
798void passArgument() {
799 useC(C());
800}
801
802// CHECK: void passArgumentByReference()
803// CHECK: 1: useCByReference
804// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class C &))
805// CHECK-NEXT: 3: C() (CXXConstructExpr, [B1.5], class C)
806// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class C)
807// CHECK-NEXT: 5: [B1.4]
808// CHECK-NEXT: 6: [B1.2]([B1.5])
809void passArgumentByReference() {
810 useCByReference(C());
811}
812
813// FIXME: Find construction context for the argument.
814// CHECK: void passArgumentWithDestructor()
815// CHECK: 1: useD
816// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(class argument_constructors::D))
817// CXX11-NEXT: 3: argument_constructors::D() (CXXConstructExpr, [B1.4], [B1.6], class argument_constructors::D)
818// CXX11-NEXT: 4: [B1.3] (BindTemporary)
819// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class argument_constructors::D)
820// CXX11-NEXT: 6: [B1.5]
821// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, class argument_constructors::D)
822// CXX11-NEXT: 8: [B1.7] (BindTemporary)
823// CXX11-NEXT: 9: [B1.2]([B1.8])
824// CXX11-NEXT: 10: ~argument_constructors::D() (Temporary object destructor)
825// CXX11-NEXT: 11: ~argument_constructors::D() (Temporary object destructor)
826// CXX17-NEXT: 3: argument_constructors::D() (CXXConstructExpr, class argument_constructors::D)
827// CXX17-NEXT: 4: [B1.3] (BindTemporary)
828// CXX17-NEXT: 5: [B1.2]([B1.4])
829// CXX17-NEXT: 6: ~argument_constructors::D() (Temporary object destructor)
830void passArgumentWithDestructor() {
831 useD(D());
832}
833
834// CHECK: void passArgumentWithDestructorByReference()
835// CHECK: 1: useDByReference
836// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class argumen
837// CHECK-NEXT: 3: argument_constructors::D() (CXXConstructExpr, [B1.4], [B1.6], class argument_c
838// CHECK-NEXT: 4: [B1.3] (BindTemporary)
839// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class argument_constructors::D)
840// CHECK-NEXT: 6: [B1.5]
841// CHECK-NEXT: 7: [B1.2]([B1.6])
842// CHECK-NEXT: 8: ~argument_constructors::D() (Temporary object destructor)
843void passArgumentWithDestructorByReference() {
844 useDByReference(D());
845}
846} // end namespace argument_constructors