blob: eaaa5786f8315ee45d73191a6e7a3d72bfc11de9 [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
453} // end namespace temporary_object_expr_without_dtors
454
455namespace temporary_object_expr_with_dtors {
456
457class D {
458public:
459 D();
460 D(int);
461 ~D();
462
463 static D get();
464
465 operator bool() const;
466};
467
468// CHECK: void simpleTemporary()
469// CHECK: 1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B1.2], class temporary_object_expr_with_dtors::D)
470// CHECK-NEXT: 2: [B1.1] (BindTemporary)
471// CHECK-NEXT: 3: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
472void simpleTemporary() {
473 D();
474}
475
476// CHECK: void temporaryInCondition()
477// CHECK: 1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B2.2], class temporary_object_expr_with_dtors::D)
478// CHECK-NEXT: 2: [B2.1] (BindTemporary)
479// CHECK-NEXT: 3: [B2.2] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
480// CHECK-NEXT: 4: [B2.3].operator bool
481// CHECK-NEXT: 5: [B2.3]
482// CHECK-NEXT: 6: [B2.5] (ImplicitCastExpr, UserDefinedConversion, _Bool)
483// CHECK-NEXT: 7: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
484// CHECK-NEXT: T: if [B2.6]
485void temporaryInCondition() {
486 if (D());
487}
488
489// CHECK: void referenceVariableWithConstructor()
490// CHECK: 1: 0
Artem Dergachevf43ac4c2018-02-24 02:00:30 +0000491// 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 +0000492// CHECK-NEXT: 3: [B1.2] (BindTemporary)
493// CHECK-NEXT: 4: [B1.3]
494// CHECK-NEXT: 5: const temporary_object_expr_with_dtors::D &d(0);
495// CHECK-NEXT: 6: [B1.5].~D() (Implicit destructor)
496void referenceVariableWithConstructor() {
497 const D &d(0);
498}
499
500// CHECK: void referenceVariableWithInitializer()
Artem Dergachev8cc55e92018-02-24 02:07:50 +0000501// 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 +0000502// CHECK-NEXT: 2: [B1.1] (BindTemporary)
503// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
504// CHECK-NEXT: 4: [B1.3]
505// CHECK-NEXT: 5: const temporary_object_expr_with_dtors::D &d = temporary_object_expr_with_dtors::D();
506// CHECK-NEXT: 6: [B1.5].~D() (Implicit destructor)
507void referenceVariableWithInitializer() {
508 const D &d = D();
509}
510
511// CHECK: void referenceVariableWithTernaryOperator(bool coin)
Artem Dergachev317291e2018-03-22 21:37:39 +0000512// CXX11: [B1]
513// CXX11-NEXT: 1: [B4.4].~D() (Implicit destructor)
514// CXX11: [B2]
515// CXX11-NEXT: 1: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
516// CXX11: [B3]
517// CXX11-NEXT: 1: ~temporary_object_expr_with_dtors::D() (Temporary object destructor)
518// CXX11: [B4]
519// CXX11-NEXT: 1: [B7.2] ? [B5.8] : [B6.8]
520// CXX11-NEXT: 2: [B4.1] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
521// CXX11-NEXT: 3: [B4.2]
522// CXX11-NEXT: 4: const temporary_object_expr_with_dtors::D &d = coin ? D::get() : temporary_object_expr_with_dtors::D(0);
523// CXX11-NEXT: T: (Temp Dtor) [B6.3]
524// CXX11: [B5]
525// CXX11-NEXT: 1: D::get
526// CXX11-NEXT: 2: [B5.1] (ImplicitCastExpr, FunctionToPointerDecay, class temporary_object_expr_with_dtors::D (*)(void))
527// CXX11-NEXT: 3: [B5.2]() (CXXRecordTypedCall, [B5.4], [B5.6])
528// CXX11-NEXT: 4: [B5.3] (BindTemporary)
529// CXX11-NEXT: 5: [B5.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
530// CXX11-NEXT: 6: [B5.5]
531// CXX11-NEXT: 7: [B5.6] (CXXConstructExpr, [B5.8], [B4.3], class temporary_object_expr_with_dtors::D)
532// CXX11-NEXT: 8: [B5.7] (BindTemporary)
533// CXX11: [B6]
534// CXX11-NEXT: 1: 0
535// CXX11-NEXT: 2: [B6.1] (CXXConstructExpr, [B6.3], [B6.6], class temporary_object_expr_with_dtors::D)
536// CXX11-NEXT: 3: [B6.2] (BindTemporary)
537// CXX11-NEXT: 4: temporary_object_expr_with_dtors::D([B6.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
538// CXX11-NEXT: 5: [B6.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
539// CXX11-NEXT: 6: [B6.5]
540// CXX11-NEXT: 7: [B6.6] (CXXConstructExpr, [B6.8], [B4.3], class temporary_object_expr_with_dtors::D)
541// CXX11-NEXT: 8: [B6.7] (BindTemporary)
542// CXX11: [B7]
543// CXX11-NEXT: 1: coin
544// CXX11-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
545// CXX11-NEXT: T: [B7.2] ? ... : ...
546// CXX17: [B1]
547// CXX17-NEXT: 1: [B4.2] ? [B2.4] : [B3.4]
548// CXX17-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
549// CXX17-NEXT: 3: [B1.2]
550// CXX17-NEXT: 4: const temporary_object_expr_with_dtors::D &d = coin ? D::get() : temporary_object_expr_with_dtors::D(0);
551// CXX17-NEXT: 5: [B1.4].~D() (Implicit destructor)
552// CXX17: [B2]
553// CXX17-NEXT: 1: D::get
554// CXX17-NEXT: 2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, class temporary_object_expr_with_dtors::D (*)(void))
555// CXX17-NEXT: 3: [B2.2]() (CXXRecordTypedCall, [B2.4], [B1.3])
556// CXX17-NEXT: 4: [B2.3] (BindTemporary)
557// CXX17: [B3]
558// CXX17-NEXT: 1: 0
559// CXX17-NEXT: 2: [B3.1] (CXXConstructExpr, [B3.3], [B1.3], class temporary_object_expr_with_dtors::D)
560// CXX17-NEXT: 3: [B3.2] (BindTemporary)
561// CXX17-NEXT: 4: temporary_object_expr_with_dtors::D([B3.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
562// CXX17: [B4]
563// CXX17-NEXT: 1: coin
564// CXX17-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
565// CXX17-NEXT: T: [B4.2] ? ... : ...
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000566void referenceVariableWithTernaryOperator(bool coin) {
567 const D &d = coin ? D::get() : D(0);
568}
Artem Dergachevceb7d912018-02-24 02:05:11 +0000569
570// CHECK: void referenceWithFunctionalCast()
571// CHECK: 1: 1
572// CHECK-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], [B1.5], class temporary_object_expr_with_dtors::D)
573// CHECK-NEXT: 3: [B1.2] (BindTemporary)
574// CHECK-NEXT: 4: temporary_object_expr_with_dtors::D([B1.3]) (CXXFunctionalCastExpr, ConstructorCon
575// CHECK-NEXT: 5: [B1.4]
576// CHECK-NEXT: 6: temporary_object_expr_with_dtors::D &&d = temporary_object_expr_with_dtors::D(1);
577// CHECK-NEXT: 7: [B1.6].~D() (Implicit destructor)
578void referenceWithFunctionalCast() {
579 D &&d = D(1);
580}
Artem Dergacheva6d91d52018-02-24 03:10:15 +0000581
582// Test the condition constructor, we don't care about branch constructors here.
583// CHECK: void constructorInTernaryCondition()
Artem Dergachev317291e2018-03-22 21:37:39 +0000584// CXX11: 1: 1
585// CXX11-NEXT: 2: [B7.1] (CXXConstructExpr, [B7.3], class temporary_object_expr_with_dtors::D)
586// CXX11-NEXT: 3: [B7.2] (BindTemporary)
587// CXX11-NEXT: 4: temporary_object_expr_with_dtors::D([B7.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
588// CXX11-NEXT: 5: [B7.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
589// CXX11-NEXT: 6: [B7.5].operator bool
590// CXX11-NEXT: 7: [B7.5]
591// CXX11-NEXT: 8: [B7.7] (ImplicitCastExpr, UserDefinedConversion, _Bool)
592// CXX11-NEXT: T: [B7.8] ? ... : ...
593// CXX17: 1: 1
594// CXX17-NEXT: 2: [B4.1] (CXXConstructExpr, [B4.3], class temporary_object_expr_with_dtors::D)
595// CXX17-NEXT: 3: [B4.2] (BindTemporary)
596// CXX17-NEXT: 4: temporary_object_expr_with_dtors::D([B4.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
597// CXX17-NEXT: 5: [B4.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
598// CXX17-NEXT: 6: [B4.5].operator bool
599// CXX17-NEXT: 7: [B4.5]
600// CXX17-NEXT: 8: [B4.7] (ImplicitCastExpr, UserDefinedConversion, _Bool)
601// CXX17-NEXT: T: [B4.8] ? ... : ...
Artem Dergacheva6d91d52018-02-24 03:10:15 +0000602void constructorInTernaryCondition() {
603 const D &d = D(1) ? D(2) : D(3);
604}
Artem Dergachev66030522018-03-01 01:09:24 +0000605
Artem Dergachev1f68d9d2018-02-15 03:13:36 +0000606} // end namespace temporary_object_expr_with_dtors
Artem Dergachev66030522018-03-01 01:09:24 +0000607
608namespace implicit_constructor_conversion {
609
610class A {};
611A get();
612
613class B {
614public:
615 B(const A &);
616 ~B() {}
617};
618
Artem Dergachev13f96642018-03-09 01:39:59 +0000619// CHECK: void implicitConstructionConversionFromTemporary()
620// CHECK: 1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
Artem Dergachev317291e2018-03-22 21:37:39 +0000621// CXX11-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
622// CXX11-NEXT: 3: [B1.2]
623// CXX11-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], [B1.8], class implicit_constructor_conversion::B)
624// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
625// CXX11-NEXT: 6: [B1.5] (BindTemporary)
626// CXX11-NEXT: 7: [B1.6] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
627// CXX11-NEXT: 8: [B1.7]
628// CXX11-NEXT: 9: [B1.8] (CXXConstructExpr, [B1.10], class implicit_constructor_conversion::B)
629// CXX11-NEXT: 10: implicit_constructor_conversion::B b = implicit_constructor_conversion::A();
630// CXX11-NEXT: 11: ~implicit_constructor_conversion::B() (Temporary object destructor)
631// CXX11-NEXT: 12: [B1.10].~B() (Implicit destructor)
632// CXX17-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
633// CXX17-NEXT: 3: [B1.2]
634// CXX17-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], class implicit_constructor_conversion::B)
635// CXX17-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
636// CXX17-NEXT: 6: implicit_constructor_conversion::B b = implicit_constructor_conversion::A();
637// CXX17-NEXT: 7: [B1.6].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000638void implicitConstructionConversionFromTemporary() {
639 B b = A();
640}
641
Artem Dergachev66030522018-03-01 01:09:24 +0000642// CHECK: void implicitConstructionConversionFromFunctionValue()
643// CHECK: 1: get
Artem Dergachev13f96642018-03-09 01:39:59 +0000644// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class implicit_constructor_conversion::A (*)(void))
Artem Dergachev1527dec2018-03-12 23:12:40 +0000645// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5])
Artem Dergachev13f96642018-03-09 01:39:59 +0000646// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
647// CHECK-NEXT: 5: [B1.4]
Artem Dergachev317291e2018-03-22 21:37:39 +0000648// CXX11-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], [B1.10], class implicit_constructor_conversion::B)
649// CXX11-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
650// CXX11-NEXT: 8: [B1.7] (BindTemporary)
651// CXX11-NEXT: 9: [B1.8] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
652// CXX11-NEXT: 10: [B1.9]
653// CXX11-NEXT: 11: [B1.10] (CXXConstructExpr, [B1.12], class implicit_constructor_conversion::B)
654// CXX11-NEXT: 12: implicit_constructor_conversion::B b = get();
655// CXX11-NEXT: 13: ~implicit_constructor_conversion::B() (Temporary object destructor)
656// CXX11-NEXT: 14: [B1.12].~B() (Implicit destructor)
657// CXX17-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], class implicit_constructor_conversion::B)
658// CXX17-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
659// CXX17-NEXT: 8: implicit_constructor_conversion::B b = get();
660// CXX17-NEXT: 9: [B1.8].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000661void implicitConstructionConversionFromFunctionValue() {
662 B b = get();
663}
664
665// CHECK: void implicitConstructionConversionFromTemporaryWithLifetimeExtension()
666// CHECK: 1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
667// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
668// CHECK-NEXT: 3: [B1.2]
669// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.7], class implicit_constructor_conversion::B)
670// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
671// CHECK-NEXT: 6: [B1.5] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
672// CHECK-NEXT: 7: [B1.6]
673// CHECK-NEXT: 8: const implicit_constructor_conversion::B &b = implicit_constructor_conversion::A();
674// CHECK-NEXT: 9: [B1.8].~B() (Implicit destructor)
675void implicitConstructionConversionFromTemporaryWithLifetimeExtension() {
676 const B &b = A();
677}
678
Artem Dergachev13f96642018-03-09 01:39:59 +0000679// CHECK: void implicitConstructionConversionFromFunctionValueWithLifetimeExtension()
680// CHECK: 1: get
Artem Dergachev66030522018-03-01 01:09:24 +0000681// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class implicit_constructor_conver
Artem Dergachev1527dec2018-03-12 23:12:40 +0000682// CHECK-NEXT: 3: [B1.2]() (CXXRecordTypedCall, [B1.5])
Artem Dergachev66030522018-03-01 01:09:24 +0000683// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
684// CHECK-NEXT: 5: [B1.4]
Artem Dergachev13f96642018-03-09 01:39:59 +0000685// CHECK-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.9], class implicit_constructor_conversion::B)
Artem Dergachev66030522018-03-01 01:09:24 +0000686// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_convers
687// CHECK-NEXT: 8: [B1.7] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
688// CHECK-NEXT: 9: [B1.8]
689// CHECK-NEXT: 10: const implicit_constructor_conversion::B &b = get();
690// CHECK-NEXT: 11: [B1.10].~B() (Implicit destructor)
Artem Dergachev13f96642018-03-09 01:39:59 +0000691void implicitConstructionConversionFromFunctionValueWithLifetimeExtension() {
Artem Dergachev66030522018-03-01 01:09:24 +0000692 const B &b = get(); // no-crash
693}
694
695} // end namespace implicit_constructor_conversion
Artem Dergachev72da02f2018-04-19 23:09:22 +0000696
697namespace argument_constructors {
698class D {
699public:
700 D();
701 ~D();
702};
703
704void useC(C c);
705void useCByReference(const C &c);
706void useD(D d);
707void useDByReference(const D &d);
708
709// FIXME: Find construction context for the argument.
710// CHECK: void passArgument()
711// CHECK: 1: useC
712// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(class C))
713// CXX11-NEXT: 3: C() (CXXConstructExpr, [B1.4], class C)
714// CXX11-NEXT: 4: [B1.3]
715// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, class C)
716// CXX11-NEXT: 6: [B1.2]([B1.5])
717// CXX17-NEXT: 3: C() (CXXConstructExpr, class C)
718// CXX17-NEXT: 4: [B1.2]([B1.3])
719void passArgument() {
720 useC(C());
721}
722
723// CHECK: void passArgumentByReference()
724// CHECK: 1: useCByReference
725// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class C &))
726// CHECK-NEXT: 3: C() (CXXConstructExpr, [B1.5], class C)
727// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class C)
728// CHECK-NEXT: 5: [B1.4]
729// CHECK-NEXT: 6: [B1.2]([B1.5])
730void passArgumentByReference() {
731 useCByReference(C());
732}
733
734// FIXME: Find construction context for the argument.
735// CHECK: void passArgumentWithDestructor()
736// CHECK: 1: useD
737// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(class argument_constructors::D))
738// CXX11-NEXT: 3: argument_constructors::D() (CXXConstructExpr, [B1.4], [B1.6], class argument_constructors::D)
739// CXX11-NEXT: 4: [B1.3] (BindTemporary)
740// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class argument_constructors::D)
741// CXX11-NEXT: 6: [B1.5]
742// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, class argument_constructors::D)
743// CXX11-NEXT: 8: [B1.7] (BindTemporary)
744// CXX11-NEXT: 9: [B1.2]([B1.8])
745// CXX11-NEXT: 10: ~argument_constructors::D() (Temporary object destructor)
746// CXX11-NEXT: 11: ~argument_constructors::D() (Temporary object destructor)
747// CXX17-NEXT: 3: argument_constructors::D() (CXXConstructExpr, class argument_constructors::D)
748// CXX17-NEXT: 4: [B1.3] (BindTemporary)
749// CXX17-NEXT: 5: [B1.2]([B1.4])
750// CXX17-NEXT: 6: ~argument_constructors::D() (Temporary object destructor)
751void passArgumentWithDestructor() {
752 useD(D());
753}
754
755// CHECK: void passArgumentWithDestructorByReference()
756// CHECK: 1: useDByReference
757// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class argumen
758// CHECK-NEXT: 3: argument_constructors::D() (CXXConstructExpr, [B1.4], [B1.6], class argument_c
759// CHECK-NEXT: 4: [B1.3] (BindTemporary)
760// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class argument_constructors::D)
761// CHECK-NEXT: 6: [B1.5]
762// CHECK-NEXT: 7: [B1.2]([B1.6])
763// CHECK-NEXT: 8: ~argument_constructors::D() (Temporary object destructor)
764void passArgumentWithDestructorByReference() {
765 useDByReference(D());
766}
767} // end namespace argument_constructors