blob: 6d92b41251466b31fb30d8f4a27c61aecda4f0dc [file] [log] [blame]
Kristof Umann85e0ff72019-04-19 23:33:50 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
2// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
3// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
Kristof Umanna3f7b582018-08-07 12:55:26 +00004// RUN: -std=c++11 -verify %s
Kristof Umann30f08652018-06-18 11:50:17 +00005
6//===----------------------------------------------------------------------===//
7// Non-polymorphic inheritance tests
8//===----------------------------------------------------------------------===//
9
10class NonPolymorphicLeft1 {
11 int x;
12
13protected:
14 int y;
15
16public:
17 NonPolymorphicLeft1() = default;
18 NonPolymorphicLeft1(int) : x(1) {}
19};
20
21class NonPolymorphicInheritanceTest1 : public NonPolymorphicLeft1 {
22 int z;
23
24public:
25 NonPolymorphicInheritanceTest1()
26 : NonPolymorphicLeft1(int{}) {
27 y = 2;
28 z = 3;
29 // All good!
30 }
31};
32
33void fNonPolymorphicInheritanceTest1() {
34 NonPolymorphicInheritanceTest1();
35}
36
37class NonPolymorphicBaseClass2 {
Kristof Umannb59b45e2018-08-21 12:16:59 +000038 int x; // expected-note{{uninitialized field 'this->NonPolymorphicBaseClass2::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +000039protected:
40 int y;
41
42public:
43 NonPolymorphicBaseClass2() = default;
44 NonPolymorphicBaseClass2(int) : x(4) {}
45};
46
47class NonPolymorphicInheritanceTest2 : public NonPolymorphicBaseClass2 {
48 int z;
49
50public:
51 NonPolymorphicInheritanceTest2() {
52 y = 5;
53 z = 6; // expected-warning{{1 uninitialized field}}
54 }
55};
56
57void fNonPolymorphicInheritanceTest2() {
58 NonPolymorphicInheritanceTest2();
59}
60
61class NonPolymorphicBaseClass3 {
62 int x;
63
64protected:
Kristof Umannb59b45e2018-08-21 12:16:59 +000065 int y; // expected-note{{uninitialized field 'this->NonPolymorphicBaseClass3::y'}}
Kristof Umann30f08652018-06-18 11:50:17 +000066public:
67 NonPolymorphicBaseClass3() = default;
68 NonPolymorphicBaseClass3(int) : x(7) {}
69};
70
71class NonPolymorphicInheritanceTest3 : public NonPolymorphicBaseClass3 {
72 int z;
73
74public:
75 NonPolymorphicInheritanceTest3()
76 : NonPolymorphicBaseClass3(int{}) {
77 z = 8; // expected-warning{{1 uninitialized field}}
78 }
79};
80
81void fNonPolymorphicInheritanceTest3() {
82 NonPolymorphicInheritanceTest3();
83}
84
85class NonPolymorphicBaseClass4 {
86 int x;
87
88protected:
89 int y;
90
91public:
92 NonPolymorphicBaseClass4() = default;
93 NonPolymorphicBaseClass4(int) : x(9) {}
94};
95
96class NonPolymorphicInheritanceTest4 : public NonPolymorphicBaseClass4 {
97 int z; // expected-note{{uninitialized field 'this->z'}}
98
99public:
100 NonPolymorphicInheritanceTest4()
101 : NonPolymorphicBaseClass4(int{}) {
102 y = 10; // expected-warning{{1 uninitialized field}}
103 }
104};
105
106void fNonPolymorphicInheritanceTest4() {
107 NonPolymorphicInheritanceTest4();
108}
109
110//===----------------------------------------------------------------------===//
111// Polymorphic inheritance tests
112//===----------------------------------------------------------------------===//
113
114class PolymorphicLeft1 {
115 int x;
116
117protected:
118 int y;
119
120public:
121 virtual ~PolymorphicLeft1() = default;
122 PolymorphicLeft1() = default;
123 PolymorphicLeft1(int) : x(11) {}
124};
125
126class PolymorphicInheritanceTest1 : public PolymorphicLeft1 {
127 int z;
128
129public:
130 PolymorphicInheritanceTest1()
131 : PolymorphicLeft1(int{}) {
132 y = 12;
133 z = 13;
134 // All good!
135 }
136};
137
138void fPolymorphicInheritanceTest1() {
139 PolymorphicInheritanceTest1();
140}
141
142class PolymorphicRight1 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000143 int x; // expected-note{{uninitialized field 'this->PolymorphicRight1::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000144protected:
145 int y;
146
147public:
148 virtual ~PolymorphicRight1() = default;
149 PolymorphicRight1() = default;
150 PolymorphicRight1(int) : x(14) {}
151};
152
153class PolymorphicInheritanceTest2 : public PolymorphicRight1 {
154 int z;
155
156public:
157 PolymorphicInheritanceTest2() {
158 y = 15;
159 z = 16; // expected-warning{{1 uninitialized field}}
160 }
161};
162
163void fPolymorphicInheritanceTest2() {
164 PolymorphicInheritanceTest2();
165}
166
167class PolymorphicBaseClass3 {
168 int x;
169
170protected:
Kristof Umannb59b45e2018-08-21 12:16:59 +0000171 int y; // expected-note{{uninitialized field 'this->PolymorphicBaseClass3::y'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000172public:
173 virtual ~PolymorphicBaseClass3() = default;
174 PolymorphicBaseClass3() = default;
175 PolymorphicBaseClass3(int) : x(17) {}
176};
177
178class PolymorphicInheritanceTest3 : public PolymorphicBaseClass3 {
179 int z;
180
181public:
182 PolymorphicInheritanceTest3()
183 : PolymorphicBaseClass3(int{}) {
184 z = 18; // expected-warning{{1 uninitialized field}}
185 }
186};
187
188void fPolymorphicInheritanceTest3() {
189 PolymorphicInheritanceTest3();
190}
191
192class PolymorphicBaseClass4 {
193 int x;
194
195protected:
196 int y;
197
198public:
199 virtual ~PolymorphicBaseClass4() = default;
200 PolymorphicBaseClass4() = default;
201 PolymorphicBaseClass4(int) : x(19) {}
202};
203
204class PolymorphicInheritanceTest4 : public PolymorphicBaseClass4 {
205 int z; // expected-note{{uninitialized field 'this->z'}}
206
207public:
208 PolymorphicInheritanceTest4()
209 : PolymorphicBaseClass4(int{}) {
210 y = 20; // expected-warning{{1 uninitialized field}}
211 }
212};
213
214void fPolymorphicInheritanceTest4() {
215 PolymorphicInheritanceTest4();
216}
217
218//===----------------------------------------------------------------------===//
219// Virtual inheritance tests
220//===----------------------------------------------------------------------===//
221
222class VirtualPolymorphicLeft1 {
223 int x;
224
225protected:
226 int y;
227
228public:
229 virtual ~VirtualPolymorphicLeft1() = default;
230 VirtualPolymorphicLeft1() = default;
231 VirtualPolymorphicLeft1(int) : x(21) {}
232};
233
234class VirtualInheritanceTest1 : virtual public VirtualPolymorphicLeft1 {
235 int z;
236
237public:
238 VirtualInheritanceTest1()
239 : VirtualPolymorphicLeft1(int()) {
240 y = 22;
241 z = 23;
242 // All good!
243 }
244};
245
246void fVirtualInheritanceTest1() {
247 VirtualInheritanceTest1();
248}
249
250class VirtualPolymorphicRight1 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000251 int x; // expected-note{{uninitialized field 'this->VirtualPolymorphicRight1::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000252protected:
253 int y;
254
255public:
256 virtual ~VirtualPolymorphicRight1() = default;
257 VirtualPolymorphicRight1() = default;
258 VirtualPolymorphicRight1(int) : x(24) {}
259};
260
261class VirtualInheritanceTest2 : virtual public VirtualPolymorphicRight1 {
262 int z;
263
264public:
265 VirtualInheritanceTest2() {
266 y = 25;
267 z = 26; // expected-warning{{1 uninitialized field}}
268 }
269};
270
271void fVirtualInheritanceTest2() {
272 VirtualInheritanceTest2();
273}
274
275class VirtualPolymorphicBaseClass3 {
276 int x;
277
278protected:
Kristof Umannb59b45e2018-08-21 12:16:59 +0000279 int y; // expected-note{{uninitialized field 'this->VirtualPolymorphicBaseClass3::y'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000280public:
281 virtual ~VirtualPolymorphicBaseClass3() = default;
282 VirtualPolymorphicBaseClass3() = default;
283 VirtualPolymorphicBaseClass3(int) : x(27) {}
284};
285
286class VirtualInheritanceTest3 : virtual public VirtualPolymorphicBaseClass3 {
287 int z;
288
289public:
290 VirtualInheritanceTest3()
291 : VirtualPolymorphicBaseClass3(int{}) {
292 z = 28; // expected-warning{{1 uninitialized field}}
293 }
294};
295
296void fVirtualInheritanceTest3() {
297 VirtualInheritanceTest3();
298}
299
300//===----------------------------------------------------------------------===//
301// Multiple inheritance tests
302//===----------------------------------------------------------------------===//
303
304/*
305 Left Right
306 \ /
307 \ /
308 \ /
309 MultipleInheritanceTest
310*/
311
312struct Left1 {
313 int x;
314 Left1() = default;
315 Left1(int) : x(29) {}
316};
317struct Right1 {
318 int y;
319 Right1() = default;
320 Right1(int) : y(30) {}
321};
322
323class MultipleInheritanceTest1 : public Left1, public Right1 {
324 int z;
325
326public:
327 MultipleInheritanceTest1()
328 : Left1(int{}),
329 Right1(char{}) {
330 z = 31;
331 // All good!
332 }
333
334 MultipleInheritanceTest1(int)
335 : Left1(int{}) {
336 y = 32;
337 z = 33;
338 // All good!
339 }
340
341 MultipleInheritanceTest1(int, int)
342 : Right1(char{}) {
343 x = 34;
344 z = 35;
345 // All good!
346 }
347};
348
349void fMultipleInheritanceTest1() {
350 MultipleInheritanceTest1();
351 MultipleInheritanceTest1(int());
352 MultipleInheritanceTest1(int(), int());
353}
354
355struct Left2 {
356 int x;
357 Left2() = default;
358 Left2(int) : x(36) {}
359};
360struct Right2 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000361 int y; // expected-note{{uninitialized field 'this->Right2::y'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000362 Right2() = default;
363 Right2(int) : y(37) {}
364};
365
366class MultipleInheritanceTest2 : public Left2, public Right2 {
367 int z;
368
369public:
370 MultipleInheritanceTest2()
371 : Left2(int{}) {
372 z = 38; // expected-warning{{1 uninitialized field}}
373 }
374};
375
376void fMultipleInheritanceTest2() {
377 MultipleInheritanceTest2();
378}
379
380struct Left3 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000381 int x; // expected-note{{uninitialized field 'this->Left3::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000382 Left3() = default;
383 Left3(int) : x(39) {}
384};
385struct Right3 {
386 int y;
387 Right3() = default;
388 Right3(int) : y(40) {}
389};
390
391class MultipleInheritanceTest3 : public Left3, public Right3 {
392 int z;
393
394public:
395 MultipleInheritanceTest3()
396 : Right3(char{}) {
397 z = 41; // expected-warning{{1 uninitialized field}}
398 }
399};
400
401void fMultipleInheritanceTest3() {
402 MultipleInheritanceTest3();
403}
404
405struct Left4 {
406 int x;
407 Left4() = default;
408 Left4(int) : x(42) {}
409};
410struct Right4 {
411 int y;
412 Right4() = default;
413 Right4(int) : y(43) {}
414};
415
416class MultipleInheritanceTest4 : public Left4, public Right4 {
417 int z; // expected-note{{uninitialized field 'this->z'}}
418
419public:
420 MultipleInheritanceTest4()
421 : Left4(int{}),
422 Right4(char{}) { // expected-warning{{1 uninitialized field}}
423 }
424};
425
426void fMultipleInheritanceTest4() {
427 MultipleInheritanceTest4();
428}
429
430struct Left5 {
431 int x;
432 Left5() = default;
433 Left5(int) : x(44) {}
434};
435struct Right5 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000436 int y; // expected-note{{uninitialized field 'this->Right5::y'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000437 Right5() = default;
438 Right5(int) : y(45) {}
439};
440
441class MultipleInheritanceTest5 : public Left5, public Right5 {
442 int z; // expected-note{{uninitialized field 'this->z'}}
443
444public:
445 MultipleInheritanceTest5() // expected-warning{{2 uninitialized fields}}
446 : Left5(int{}) {
447 }
448};
449
450void fMultipleInheritanceTest5() {
451 MultipleInheritanceTest5();
452}
453
454//===----------------------------------------------------------------------===//
455// Non-virtual diamond inheritance tests
456//===----------------------------------------------------------------------===//
457
458/*
459 NonVirtualBase NonVirtualBase
460 | |
461 | |
462 | |
463 First Second
464 \ /
465 \ /
466 \ /
467 NonVirtualDiamondInheritanceTest
468*/
469
470struct NonVirtualBase1 {
471 int x;
472 NonVirtualBase1() = default;
473 NonVirtualBase1(int) : x(46) {}
474};
475struct First1 : public NonVirtualBase1 {
476 First1() = default;
477 First1(int) : NonVirtualBase1(int{}) {}
478};
479struct Second1 : public NonVirtualBase1 {
480 Second1() = default;
481 Second1(int) : NonVirtualBase1(int{}) {}
482};
483
484class NonVirtualDiamondInheritanceTest1 : public First1, public Second1 {
485 int z;
486
487public:
488 NonVirtualDiamondInheritanceTest1()
489 : First1(int{}),
490 Second1(int{}) {
491 z = 47;
492 // All good!
493 }
494
495 NonVirtualDiamondInheritanceTest1(int)
496 : First1(int{}) {
497 Second1::x = 48;
498 z = 49;
499 // All good!
500 }
501
502 NonVirtualDiamondInheritanceTest1(int, int)
503 : Second1(int{}) {
504 First1::x = 50;
505 z = 51;
506 // All good!
507 }
508};
509
510void fNonVirtualDiamondInheritanceTest1() {
511 NonVirtualDiamondInheritanceTest1();
512 NonVirtualDiamondInheritanceTest1(int());
513 NonVirtualDiamondInheritanceTest1(int(), int());
514}
515
516struct NonVirtualBase2 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000517 int x; // expected-note{{uninitialized field 'this->NonVirtualBase2::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000518 NonVirtualBase2() = default;
519 NonVirtualBase2(int) : x(52) {}
520};
521struct First2 : public NonVirtualBase2 {
522 First2() = default;
523 First2(int) : NonVirtualBase2(int{}) {}
524};
525struct Second2 : public NonVirtualBase2 {
526 Second2() = default;
527 Second2(int) : NonVirtualBase2(int{}) {}
528};
529
530class NonVirtualDiamondInheritanceTest2 : public First2, public Second2 {
531 int z;
532
533public:
534 NonVirtualDiamondInheritanceTest2()
535 : First2(int{}) {
536 z = 53; // expected-warning{{1 uninitialized field}}
537 }
538};
539
540void fNonVirtualDiamondInheritanceTest2() {
541 NonVirtualDiamondInheritanceTest2();
542}
543
544struct NonVirtualBase3 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000545 int x; // expected-note{{uninitialized field 'this->NonVirtualBase3::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000546 NonVirtualBase3() = default;
547 NonVirtualBase3(int) : x(54) {}
548};
549struct First3 : public NonVirtualBase3 {
550 First3() = default;
551 First3(int) : NonVirtualBase3(int{}) {}
552};
553struct Second3 : public NonVirtualBase3 {
554 Second3() = default;
555 Second3(int) : NonVirtualBase3(int{}) {}
556};
557
558class NonVirtualDiamondInheritanceTest3 : public First3, public Second3 {
559 int z;
560
561public:
562 NonVirtualDiamondInheritanceTest3()
563 : Second3(int{}) {
564 z = 55; // expected-warning{{1 uninitialized field}}
565 }
566};
567
568void fNonVirtualDiamondInheritanceTest3() {
569 NonVirtualDiamondInheritanceTest3();
570}
571
572struct NonVirtualBase4 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000573 int x; // expected-note{{uninitialized field 'this->NonVirtualBase4::x'}}
574 // expected-note@-1{{uninitialized field 'this->NonVirtualBase4::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000575 NonVirtualBase4() = default;
576 NonVirtualBase4(int) : x(56) {}
577};
578struct First4 : public NonVirtualBase4 {
579 First4() = default;
580 First4(int) : NonVirtualBase4(int{}) {}
581};
582struct Second4 : public NonVirtualBase4 {
583 Second4() = default;
584 Second4(int) : NonVirtualBase4(int{}) {}
585};
586
587class NonVirtualDiamondInheritanceTest4 : public First4, public Second4 {
588 int z;
589
590public:
591 NonVirtualDiamondInheritanceTest4() {
592 z = 57; // expected-warning{{2 uninitialized fields}}
593 }
594};
595
596void fNonVirtualDiamondInheritanceTest4() {
597 NonVirtualDiamondInheritanceTest4();
598}
599
600struct NonVirtualBase5 {
601 int x;
602 NonVirtualBase5() = default;
603 NonVirtualBase5(int) : x(58) {}
604};
605struct First5 : public NonVirtualBase5 {
606 First5() = default;
607 First5(int) : NonVirtualBase5(int{}) {}
608};
609struct Second5 : public NonVirtualBase5 {
610 Second5() = default;
611 Second5(int) : NonVirtualBase5(int{}) {}
612};
613
614class NonVirtualDiamondInheritanceTest5 : public First5, public Second5 {
615 int z; // expected-note{{uninitialized field 'this->z'}}
616
617public:
618 NonVirtualDiamondInheritanceTest5()
619 : First5(int{}),
620 Second5(int{}) { // expected-warning{{1 uninitialized field}}
621 }
622};
623
624void fNonVirtualDiamondInheritanceTest5() {
625 NonVirtualDiamondInheritanceTest5();
626}
627
628struct NonVirtualBase6 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000629 int x; // expected-note{{uninitialized field 'this->NonVirtualBase6::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000630 NonVirtualBase6() = default;
631 NonVirtualBase6(int) : x(59) {}
632};
633struct First6 : public NonVirtualBase6 {
634 First6() = default;
635 First6(int) : NonVirtualBase6(int{}) {}
636};
637struct Second6 : public NonVirtualBase6 {
638 Second6() = default;
639 Second6(int) : NonVirtualBase6(int{}) {}
640};
641
642class NonVirtualDiamondInheritanceTest6 : public First6, public Second6 {
643 int z; // expected-note{{uninitialized field 'this->z'}}
644
645public:
646 NonVirtualDiamondInheritanceTest6() // expected-warning{{2 uninitialized fields}}
647 : First6(int{}) {
648 // 'z' and 'Second::x' unintialized
649 }
650};
651
652void fNonVirtualDiamondInheritanceTest6() {
653 NonVirtualDiamondInheritanceTest6();
654}
655
656//===----------------------------------------------------------------------===//
657// Virtual diamond inheritance tests
658//===----------------------------------------------------------------------===//
659
660/*
661 VirtualBase
662 / \
663 / \
664 / \
665 VirtualFirst VirtualSecond
666 \ /
667 \ /
668 \ /
669 VirtualDiamondInheritanceTest
670*/
671
672struct VirtualBase1 {
673 int x;
674 VirtualBase1() = default;
675 VirtualBase1(int) : x(60) {}
676};
677struct VirtualFirst1 : virtual public VirtualBase1 {
678 VirtualFirst1() = default;
679 VirtualFirst1(int) : VirtualBase1(int{}) {}
680 VirtualFirst1(int, int) { x = 61; }
681};
682struct VirtualSecond1 : virtual public VirtualBase1 {
683 VirtualSecond1() = default;
684 VirtualSecond1(int) : VirtualBase1(int{}) {}
685 VirtualSecond1(int, int) { x = 62; }
686};
687
688class VirtualDiamondInheritanceTest1 : public VirtualFirst1, public VirtualSecond1 {
689
690public:
691 VirtualDiamondInheritanceTest1() {
692 x = 0;
693 // All good!
694 }
695
696 VirtualDiamondInheritanceTest1(int)
697 : VirtualFirst1(int{}, int{}),
698 VirtualSecond1(int{}, int{}) {
699 // All good!
700 }
701
702 VirtualDiamondInheritanceTest1(int, int)
703 : VirtualFirst1(int{}, int{}) {
704 // All good!
705 }
706};
707
708void fVirtualDiamondInheritanceTest1() {
709 VirtualDiamondInheritanceTest1();
710 VirtualDiamondInheritanceTest1(int());
711 VirtualDiamondInheritanceTest1(int(), int());
712}
713
714struct VirtualBase2 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000715 int x; // expected-note{{uninitialized field 'this->VirtualBase2::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000716 VirtualBase2() = default;
717 VirtualBase2(int) : x(63) {}
718};
719struct VirtualFirst2 : virtual public VirtualBase2 {
720 VirtualFirst2() = default;
721 VirtualFirst2(int) : VirtualBase2(int{}) {}
722 VirtualFirst2(int, int) { x = 64; }
723};
724struct VirtualSecond2 : virtual public VirtualBase2 {
725 VirtualSecond2() = default;
726 VirtualSecond2(int) : VirtualBase2(int{}) {}
727 VirtualSecond2(int, int) { x = 65; }
728};
729
730class VirtualDiamondInheritanceTest2 : public VirtualFirst2, public VirtualSecond2 {
731
732public:
733 VirtualDiamondInheritanceTest2() // expected-warning{{1 uninitialized field}}
734 : VirtualFirst2(int{}) {
735 // From the N4659 C++ Standard Working Draft:
736 //
737 // (15.6.2.7)
738 // [...] A 'mem-initializer' where the 'mem-initializer-id' denotes a
739 // virtual base class is ignored during execution of a constructor of any
740 // class that is not the most derived class.
741 //
742 // This means that Left1::x will not be initialized, because in both
743 // VirtualFirst::VirtualFirst(int) and VirtualSecond::VirtualSecond(int)
744 // the constructor delegation to Left1::Left1(int) will be
745 // ignored.
746 }
747};
748
749void fVirtualDiamondInheritanceTest2() {
750 VirtualDiamondInheritanceTest2();
751}
752
753struct VirtualBase3 {
Kristof Umannb59b45e2018-08-21 12:16:59 +0000754 int x; // expected-note{{uninitialized field 'this->VirtualBase3::x'}}
Kristof Umann30f08652018-06-18 11:50:17 +0000755 VirtualBase3() = default;
756 VirtualBase3(int) : x(66) {}
757};
758struct VirtualFirst3 : virtual public VirtualBase3 {
759 VirtualFirst3() = default;
760 VirtualFirst3(int) : VirtualBase3(int{}) {}
761 VirtualFirst3(int, int) { x = 67; }
762};
763struct VirtualSecond3 : virtual public VirtualBase3 {
764 VirtualSecond3() = default;
765 VirtualSecond3(int) : VirtualBase3(int{}) {}
766 VirtualSecond3(int, int) { x = 68; }
767};
768
769class VirtualDiamondInheritanceTest3 : public VirtualFirst3, public VirtualSecond3 {
770
771public:
772 VirtualDiamondInheritanceTest3() // expected-warning{{1 uninitialized field}}
773 : VirtualFirst3(int{}) {}
774};
775
776void fVirtualDiamondInheritanceTest3() {
777 VirtualDiamondInheritanceTest3();
778}
Kristof Umannef9af052018-08-08 13:18:53 +0000779
780//===----------------------------------------------------------------------===//
781// Dynamic type test.
782//===----------------------------------------------------------------------===//
783
Kristof Umann3ef3dd72018-09-14 09:13:36 +0000784struct DynTBase1 {};
785struct DynTDerived1 : DynTBase1 {
786 int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived1 *>(this->bptr)->y'}}
Kristof Umannef9af052018-08-08 13:18:53 +0000787};
788
Kristof Umann3ef3dd72018-09-14 09:13:36 +0000789struct DynamicTypeTest1 {
790 DynTBase1 *bptr;
Kristof Umannef9af052018-08-08 13:18:53 +0000791 int i = 0;
792
Kristof Umann3ef3dd72018-09-14 09:13:36 +0000793 DynamicTypeTest1(DynTBase1 *bptr) : bptr(bptr) {} // expected-warning{{1 uninitialized field}}
Kristof Umannef9af052018-08-08 13:18:53 +0000794};
795
Kristof Umann3ef3dd72018-09-14 09:13:36 +0000796void fDynamicTypeTest1() {
797 DynTDerived1 d;
798 DynamicTypeTest1 t(&d);
Kristof Umannef9af052018-08-08 13:18:53 +0000799};
Kristof Umann3ef3dd72018-09-14 09:13:36 +0000800
801struct DynTBase2 {
802 int x; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->DynTBase2::x'}}
803};
804struct DynTDerived2 : DynTBase2 {
805 int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->y'}}
806};
807
808struct DynamicTypeTest2 {
809 DynTBase2 *bptr;
810 int i = 0;
811
812 DynamicTypeTest2(DynTBase2 *bptr) : bptr(bptr) {} // expected-warning{{2 uninitialized fields}}
813};
814
815void fDynamicTypeTest2() {
816 DynTDerived2 d;
817 DynamicTypeTest2 t(&d);
818}
819
820struct SymbolicSuperRegionBase {
821 SymbolicSuperRegionBase() {}
822};
823
824struct SymbolicSuperRegionDerived : SymbolicSuperRegionBase {
825 SymbolicSuperRegionBase *bptr; // no-crash
826 SymbolicSuperRegionDerived(SymbolicSuperRegionBase *bptr) : bptr(bptr) {}
827};
828
829SymbolicSuperRegionDerived *getSymbolicRegion();
830
831void fSymbolicSuperRegionTest() {
832 SymbolicSuperRegionDerived test(getSymbolicRegion());
833}