Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wplacement-new-size-7.C

raw
1 /* PR c++/96511 - Incorrect -Wplacement-new on POINTER_PLUS into an array
2 with 4-byte elements
3 { dg-do compile }
4 { dg-options "-Wall" } */
5
6 typedef __INT16_TYPE__ int16_t;
7 typedef __INT32_TYPE__ int32_t;
8 typedef __SIZE_TYPE__ size_t;
9
10 void* operator new (size_t, void *p) { return p; }
11
12 void test_a1_int16 ()
13 {
14 int16_t a3[3]; // { dg-message "declared here" }
15
16 new (a3) int16_t;
17 new (a3 + 1) int16_t;
18 new (a3 + 2) int16_t; // { dg-bogus "\\\[-Wplacement-new" }
19 new (&a3[1]) int16_t;
20 new (&a3[0] + 1) int16_t;
21 new (&a3[0] + 2) int16_t; // { dg-bogus "\\\[-Wplacement-new" }
22 new (&a3[0] + 3) int16_t; // { dg-warning "\\\[-Wplacement-new" }
23 }
24
25 void test_a1_int32 ()
26 {
27 int16_t a3[3];
28
29 new (a3 + 1) int32_t; // { dg-bogus "\\\[-Wplacement-new" }
30 new (&a3[1]) int32_t;
31 new (&a3[0] + 1) int32_t; // { dg-bogus "\\\[-Wplacement-new" }
32 new (&a3[0] + 2) int32_t; // { dg-warning "\\\[-Wplacement-new" }
33 }
34
35
36 void test_a2 ()
37 {
38 int16_t a23[2][3];
39
40 new (a23 + 1) int16_t; // { dg-bogus "\\\[-Wplacement-new" }
41 new (&a23[1]) int16_t;
42 new (&a23[2]) int16_t; // { dg-warning "\\\[-Wplacement-new" }
43
44 new (&a23[0][0] + 1) int16_t;
45 new (&a23[0][0] + 2) int16_t;
46 // Deriving a pointer to the next array from one to an element of
47 // the prior array isn't valid even if the resulting pointer points
48 // to an element of the larger array. Verify it's diagnosed.
49 new (&a23[0][0] + 3) int16_t; // { dg-warning "\\\[-Wplacement-new" }
50 new (&a23[0][0] + 4) int16_t; // { dg-warning "\\\[-Wplacement-new" }
51 new (&a23[0][0] + 5) int16_t; // { dg-warning "\\\[-Wplacement-new" }
52 new (&a23[0][0] + 6) int16_t; // { dg-warning "\\\[-Wplacement-new" }
53
54 new (&a23[0][1] + 1) int16_t;
55 new (&a23[0][1] + 2) int16_t; // { dg-warning "\\\[-Wplacement-new" }
56 new (&a23[0][1] + 3) int16_t; // { dg-warning "\\\[-Wplacement-new" }
57 new (&a23[0][1] + 4) int16_t; // { dg-warning "\\\[-Wplacement-new" }
58 new (&a23[0][1] + 5) int16_t; // { dg-warning "\\\[-Wplacement-new" }
59 new (&a23[0][1] + 6) int16_t; // { dg-warning "\\\[-Wplacement-new" }
60
61 new (&a23[0][2] + 1) int16_t; // { dg-warning "\\\[-Wplacement-new" }
62 new (&a23[0][2] + 2) int16_t; // { dg-warning "\\\[-Wplacement-new" }
63 new (&a23[0][2] + 3) int16_t; // { dg-warning "\\\[-Wplacement-new" }
64 new (&a23[0][2] + 4) int16_t; // { dg-warning "\\\[-Wplacement-new" }
65 new (&a23[0][2] + 5) int16_t; // { dg-warning "\\\[-Wplacement-new" }
66 new (&a23[0][2] + 6) int16_t; // { dg-warning "\\\[-Wplacement-new" }
67
68 new (&a23[1][0]) int16_t;
69 new (&a23[1][0] + 1) int16_t;
70 new (&a23[1][0] + 2) int16_t;
71 new (&a23[1][0] + 3) int16_t; // { dg-warning "\\\[-Wplacement-new" }
72 new (&a23[1][0] + 4) int16_t; // { dg-warning "\\\[-Wplacement-new" }
73
74 new (&a23[1][1]) int16_t;
75 new (&a23[1][2]) int16_t;
76 new (&a23[1][2] + 1) int16_t; // { dg-warning "\\\[-Wplacement-new" }
77 new (&a23[1][3]) int16_t; // { dg-warning "\\\[-Wplacement-new" }
78 new (&a23[1][3] + 1) int16_t; // { dg-warning "\\\[-Wplacement-new" }
79
80 new (&a23[2][0]) int16_t; // { dg-warning "\\\[-Wplacement-new" }
81 new (&a23[2][0] + 1) int16_t; // { dg-warning "\\\[-Wplacement-new" }
82 }