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