Debian Codegraph @

gcc/testsuite/g++.dg/warn/Warray-bounds-19.C

raw
1 /* PR middle-end/98266 - bogus array subscript is partly outside array
2 bounds on virtual inheritance
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 void* operator new (__SIZE_TYPE__, void *p) { return p; }
7 void* operator new[] (__SIZE_TYPE__, void *p) { return p; }
8
9
10 struct A
11 {
12 virtual ~A ();
13 int ai;
14 };
15
16 struct B: virtual A { };
17
18
19 // Exercise access to base members by ctor of the most derived class.
20
21 struct C1: virtual A // { dg-bogus "\\\[-Warray-bounds" }
22 {
23 int c1i;
24 C1 ();
25 };
26
27 struct D1: virtual B, virtual C1
28 {
29 D1 () { ai = 0; c1i = 1; };
30 };
31
32 void sink (void*);
33
34 void nowarn_derived_ctor_access_decl ()
35 {
36 D1 d1;
37 sink (&d1);
38 }
39
40 void nowarn_derived_ctor_access_new ()
41 {
42 D1 *p = new D1;
43 sink (p);
44 }
45
46 void nowarn_derived_ctor_access_placement_new ()
47 {
48 char a[sizeof (D1)];
49 D1 *p = new (a) D1;
50 sink (p);
51 }
52
53 void nowarn_derived_ctor_access_new_array ()
54 {
55 D1 *p = new D1[2];
56 sink (p);
57 }
58
59 void nowarn_derived_ctor_access_placement_new_array ()
60 {
61 char a[sizeof (D1) * 2];
62 D1 *p = new (a) D1[2];
63 sink (p);
64 }
65
66
67 // Exercise access to base members by ctor of the second most derived class.
68
69 struct C2: virtual A
70 {
71 int c2i;
72 ~C2 () { ai = 0; c2i = 1; } // { dg-bogus "\\\[-Warray-bounds"
73 };
74
75 struct D2: virtual B, virtual C2
76 {
77 D2 ();
78 };
79
80 void nowarn_base_dtor_access_decl ()
81 {
82 D2 d2;
83 sink (&d2);
84 }
85
86 void nowarn_base_dtor_access_new ()
87 {
88 D2 *p = new D2;
89 sink (p);
90 }
91
92 void nowarn_base_dtor_access_placement_new ()
93 {
94 char a[sizeof (D2)];
95 D2 *p = new (a) D2;
96 sink (p);
97 }
98
99 void nowarn_base_dtor_access_new_array ()
100 {
101 D2 *p = new D2[2];
102 sink (p);
103 }
104
105 void nowarn_base_dtor_access_placement_new_array ()
106 {
107 char a[sizeof (D2) * 2];
108 D2 *p = new (a) D2[2];
109 sink (p);
110 }