Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / warn / Warray-bounds-10.C
blob4b758aadaa164adffa6a9f42190cf9eb3c4048e2
1 /* PR c++/97201 - ICE in -Warray-bounds writing to result of operator new(0)
2    Verify that out-of-bounds accesses to memory returned by default operator
3    new() are diagnosed.
4    { dg-do compile }
5    { dg-options "-O2 -Wall -Warray-bounds -ftrack-macro-expansion=0" } */
7 typedef __INT32_TYPE__ int32_t;
9 void sink (void*);
11 #define OP_NEW(n)  operator new (n)
12 #define T(T, n, i) do {                         \
13     T *p = (T*) OP_NEW (n);                     \
14     p[i] = 0;                                   \
15     sink (p);                                   \
16   } while (0)
18 void warn_op_new ()
20   T (int32_t, 0, 0);          // { dg-warning "array subscript 0 is outside array bounds of 'int32_t \\\[0]'" }
21                               // { dg-message "object of size \\d allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" { target *-*-* } .-1 }
22   T (int32_t, 1, 0);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[1]'" }
23   T (int32_t, 2, 0);         //  { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[2]'" }
24   T (int32_t, 3, 0);         // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[3]'" }
26   T (int32_t, 4, 0);
28   T (int32_t, 0, 1);          // { dg-warning "array subscript 1 is outside array bounds of 'int32_t \\\[0]'" }
29   T (int32_t, 1, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
30   T (int32_t, 2, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
31   T (int32_t, 3, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
32   T (int32_t, 4, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
33   T (int32_t, 5, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[5]" }
34   T (int32_t, 6, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[6]" }
35   T (int32_t, 7, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[7]" }
37   T (int32_t, 8, 1);
41 void warn_op_array_new ()
43 #undef OP_NEW
44 #define OP_NEW(n)  operator new[] (n)
46   T (int32_t, 0, 0);          // { dg-warning "array subscript 0 is outside array bounds of 'int32_t \\\[0]'" }
47                               // { dg-message "object of size \\d allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" { target *-*-* } .-1 }
48   T (int32_t, 1, 0);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[1]'" }
49   T (int32_t, 2, 0);         //  { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[2]'" }
50   T (int32_t, 3, 0);         // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[3]'" }
52   T (int32_t, 4, 0);
54   T (int32_t, 0, 1);          // { dg-warning "array subscript 1 is outside array bounds of 'int32_t \\\[0]'" }
55   T (int32_t, 1, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
56   T (int32_t, 2, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
57   T (int32_t, 3, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
58   T (int32_t, 4, 1);          // { dg-warning "array subscript 1 is outside array bounds " }
59   T (int32_t, 5, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[5]" }
60   T (int32_t, 6, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[6]" }
61   T (int32_t, 7, 1);          // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[7]" }
63   T (int32_t, 8, 1);