]>
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" } | |
c232f07b | 30 | ci = 0; // { dg-warning "\\\[-Warray-bounds" "assign" { xfail lp64 } } |
f3daa6c0 MS |
31 | } |
32 | }; | |
33 | ||
34 | void sink (void*); | |
35 | ||
36 | void warn_derived_ctor_access_new_decl () | |
37 | { | |
c232f07b MS |
38 | char a[sizeof (D1)]; // { dg-message "at offset 1 into object 'a' of size 40" "LP64 note" { target lp64} } |
39 | // { dg-message "at offset 1 into object 'a' of size 20" "LP64 note" { target ilp32} .-1 } | |
f3daa6c0 MS |
40 | char *p = a; |
41 | ++p; | |
42 | D1 *q = new (p) D1; | |
43 | sink (q); | |
44 | } | |
45 | ||
46 | void warn_derived_ctor_access_new_alloc () | |
47 | { | |
a1108556 | 48 | 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 |
49 | ++p; |
50 | D1 *q = new (p) D1; | |
51 | sink (q); | |
52 | } | |
53 | ||
54 | void warn_derived_ctor_access_new_array_decl () | |
55 | { | |
c232f07b MS |
56 | char b[sizeof (D1) * 2]; // { dg-message "at offset \\d+ into object 'b' of size 80" "LP64 note" { target lp64 } } |
57 | // { dg-message "at offset \\d+ into object 'b' of size 40" "LP64 note" { target ilp32 } .-1 } | |
f3daa6c0 MS |
58 | char *p = b; |
59 | ++p; | |
60 | D1 *q = new (p) D1[2]; | |
61 | sink (q); | |
62 | } | |
63 | ||
64 | void warn_derived_ctor_access_new_array_alloc () | |
65 | { | |
a1108556 | 66 | 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 |
67 | ++p; |
68 | D1 *q = new (p) D1[2]; | |
69 | sink (q); | |
70 | } |