Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / warn / Warray-bounds-24.C
blob071453a485d7023087b9a4cccfd44850e511d236
1 /* PR middle-end/99502 - missing -Warray-bounds on partial out of bounds
2    access in C++
3    { dg-do compile }
4    { dg-options "-O2 -Wall" } */
6 inline void* operator new (__SIZE_TYPE__, void *p) { return p; }
8 struct B0 { int b0i, b0a[0]; };
9 struct B1: virtual B0 { int b1i, b1a[0]; };
10 struct B2: virtual B0 { int b2i, b2a[0]; };
11 struct D1: B1, B2 { int d1i, d1a[0]; };
12 struct D2: D1 { int d2i, d2a[0]; };
13 struct D3: D2 { int d3i, d3a[0]; };
15 void sink (void*);
18 void test_D1 ()
20   {
21     char *p = new char[sizeof (D1)];
22     new (p) D1 ();
23     sink (p);
24   }
26   {
27     char *p = new char[sizeof (D1) - 1];
28     new (p) D1 ();                      // { dg-warning "-Warray-bounds" }
29     sink (p);
30   }
33 void test_D1_b0a ()
35   {
36     D1 *p = (D1*)new char[sizeof (D1)];
37     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
38     sink (p);
39   }
41   {
42     D1 *p = (D1*)new char[3];
43     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" }
44     sink (p);
45   }
48 void test_D1_b1a ()
50   {
51     D1 *p = (D1*)new char[sizeof (D1)];
52     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
53     sink (p);
54   }
56   {
57     D1 *p = (D1*)new char[3];
58     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
59     sink (p);
60   }
63 void test_D1_b2a ()
65   {
66     D1 *p = (D1*)new char[sizeof (D1)];
67     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
68     sink (p);
69   }
71   {
72     D1 *p = (D1*)new char[3];
73     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
74     sink (p);
75   }
78 void test_D1_d1a ()
80   {
81     D1 *p = (D1*)new char[sizeof (D1)];
82     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
83     sink (p);
84   }
86   {
87     D1 *p = (D1*)new char[3];
88     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
89     sink (p);
90   }
94 void test_D2 ()
96   {
97     char *p = new char[sizeof (D2)];
98     new (p) D2 ();
99     sink (p);
100   }
102   {
103     char *p = new char[sizeof (D2) - 1];
104     new (p) D2 ();                      // { dg-warning "-Warray-bounds" }
105     sink (p);
106   }
109 void test_D2_b0a ()
111   {
112     D2 *p = (D2*)new char[sizeof (D2)];
113     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
114     sink (p);
115   }
117   {
118     D2 *p = (D2*)new char[3];
119     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" }
120     sink (p);
121   }
124 void test_D2_b1a ()
126   {
127     D2 *p = (D2*)new char[sizeof (D2)];
128     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
129     sink (p);
130   }
132   {
133     D2 *p = (D2*)new char[3];
134     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
135     sink (p);
136   }
139 void test_D2_b2a ()
141   {
142     D2 *p = (D2*)new char[sizeof (D2)];
143     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
144     sink (p);
145   }
147   {
148     D2 *p = (D2*)new char[3];
149     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
150     sink (p);
151   }
154 void test_D2_d1a ()
156   {
157     D2 *p = (D2*)new char[sizeof (D2)];
158     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
159     sink (p);
160   }
162   {
163     D2 *p = (D2*)new char[3];
164     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
165     sink (p);
166   }
169 void test_D2_d2a ()
171   {
172     D2 *p = (D2*)new char[sizeof (D2)];
173     *p->d2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
174     sink (p);
175   }
177   {
178     D2 *p = (D2*)new char[3];
179     *p->d2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
180     sink (p);
181   }
185 void test_D3 ()
187   {
188     char *p = new char[sizeof (D3)];
189     new (p) D3 ();
190     sink (p);
191   }
193   {
194     char *p = new char[sizeof (D3) - 1];
195     new (p) D3 ();                      // { dg-warning "-Warray-bounds" }
196     sink (p);
197   }
200 void test_D3_b0a ()
202   {
203     D3 *p = (D3*)new char[sizeof (D3)];
204     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
205     sink (p);
206   }
208   {
209     D3 *p = (D3*)new char[3];
210     *p->b0a = __LINE__;                 // { dg-warning "-Warray-bounds" }
211     sink (p);
212   }
215 void test_D3_b1a ()
217   {
218     D3 *p = (D3*)new char[sizeof (D3)];
219     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
220     sink (p);
221   }
223   {
224     D3 *p = (D3*)new char[3];
225     *p->b1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
226     sink (p);
227   }
230 void test_D3_b2a ()
232   {
233     D3 *p = (D3*)new char[sizeof (D3)];
234     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
235     sink (p);
236   }
238   {
239     D3 *p = (D3*)new char[3];
240     *p->b2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
241     sink (p);
242   }
245 void test_D3_d1a ()
247   {
248     D3 *p = (D3*)new char[sizeof (D3)];
249     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
250     sink (p);
251   }
253   {
254     D3 *p = (D3*)new char[3];
255     *p->d1a = __LINE__;                 // { dg-warning "-Warray-bounds" }
256     sink (p);
257   }
260 void test_D3_d2a ()
262   {
263     D3 *p = (D3*)new char[sizeof (D3)];
264     *p->d2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
265     sink (p);
266   }
268   {
269     D3 *p = (D3*)new char[3];
270     *p->d2a = __LINE__;                 // { dg-warning "-Warray-bounds" }
271     sink (p);
272   }
275 void test_D3_d3a ()
277   {
278     D3 *p = (D3*)new char[sizeof (D3)];
279     *p->d3a = __LINE__;                 // { dg-warning "-Warray-bounds" }
280     sink (p);
281   }
283   {
284     D3 *p = (D3*)new char[3];
285     *p->d3a = __LINE__;                 // { dg-warning "-Warray-bounds" }
286     sink (p);
287   }