]>
Commit | Line | Data |
---|---|---|
f3daa6c0 MS |
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 | int ai; | |
13 | virtual ~A (); | |
14 | }; | |
15 | ||
16 | struct B: virtual A { }; | |
17 | ||
18 | struct C: virtual A | |
19 | { | |
20 | int ci; | |
21 | C (); | |
22 | }; | |
23 | ||
24 | struct D1: virtual B, virtual C | |
25 | { | |
26 | /* The warning would ideally point to the assignment but instead points | |
27 | to the opening brace. */ | |
28 | D1 () | |
29 | { // { dg-warning "\\\[-Warray-bounds" "brace" } | |
30 | ci = 0; // { dg-warning "\\\[-Warray-bounds" "assign" { xfail *-*-* } } | |
31 | } | |
32 | }; | |
33 | ||
34 | void sink (void*); | |
35 | ||
36 | void warn_derived_ctor_access_new_decl () | |
37 | { | |
a1108556 | 38 | char a[sizeof (D1)]; // { dg-message "at offset 1 into object 'a' of size 40" "note" } |
f3daa6c0 MS |
39 | char *p = a; |
40 | ++p; | |
41 | D1 *q = new (p) D1; | |
42 | sink (q); | |
43 | } | |
44 | ||
45 | void warn_derived_ctor_access_new_alloc () | |
46 | { | |
a1108556 | 47 | char *p = (char*)operator new (sizeof (D1)); // { dg-message "at offset 1 into object of size \\d+ allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" } |
f3daa6c0 MS |
48 | ++p; |
49 | D1 *q = new (p) D1; | |
50 | sink (q); | |
51 | } | |
52 | ||
53 | void warn_derived_ctor_access_new_array_decl () | |
54 | { | |
a1108556 | 55 | char b[sizeof (D1) * 2]; // { dg-message "at offset \\d+ into object 'b' of size 80" "note" } |
f3daa6c0 MS |
56 | char *p = b; |
57 | ++p; | |
58 | D1 *q = new (p) D1[2]; | |
59 | sink (q); | |
60 | } | |
61 | ||
62 | void warn_derived_ctor_access_new_array_alloc () | |
63 | { | |
a1108556 | 64 | char *p = new char[sizeof (D1) * 2]; // { dg-message "at offset \\d+ into object of size \\d+ allocated by '\[^\n\r]*operator new\[^\n\r]*" "note" } |
f3daa6c0 MS |
65 | ++p; |
66 | D1 *q = new (p) D1[2]; | |
67 | sink (q); | |
68 | } |