Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-7.C

raw
1 /* PR middle-end/101791 - missing warning on a mismatch between scalar
2 and array forms of new and delete
3 Verify that likely safe calls to technically mismatched member operator
4 new and delete are not diagnosed. This test might need to be adjusted
5 if it turns out the assumptions GCC makes are overly conservative.
6 { dg-do compile }
7 { dg-options "-Wall" } */
8
9 typedef __SIZE_TYPE__ size_t;
10
11 namespace std
12 {
13 #if __cplusplus >= 201703L
14 enum class align_val_t: size_t { };
15 #else
16 enum align_val_t { };
17 #endif
18
19 struct nothrow_t { };
20 const nothrow_t nothrow = { };
21
22 }
23
24 void sink (void*, ...);
25
26 struct X { } x;
27 struct Y { } y;
28
29 struct A
30 {
31 void* operator new (size_t);
32 void* operator new (size_t, std::align_val_t);
33
34 void* operator new (size_t, X);
35 void* operator new (size_t, Y);
36
37 void* operator new (size_t, std::align_val_t, X);
38 void* operator new (size_t, std::nothrow_t, Y);
39
40 /* A single operator delete callable on the result of calls to any
41 of the operator new overloads above (this may be too optimistic). */
42 void operator delete (void*);
43 };
44
45 A* nowarn_align ()
46 {
47 /* The following are likely okay given A's definition above but would
48 not be if A also defined an align_val_t overload of operator delete. */
49 A *p = new (std::align_val_t (8)) A;
50 delete p;
51
52 return new (std::align_val_t (16)) A;
53 }
54
55 A* nowarn_X ()
56 {
57 /* The following are also likely okay given A's definition above but
58 also would not be if A also defined an overload of operator delete
59 for X. */
60 A *p = new (x) A;
61 delete p;
62 return new (x) A;
63 }
64
65 A* nowarn_Y ()
66 {
67 // Same as above.
68 A *p = new (y) A;
69 delete p;
70 return new (y) A;
71 }
72
73
74 A* nowarn_align_X ()
75 {
76 // Same as above.
77 A *p = new (std::align_val_t (32), x) A;
78 delete p;
79
80 return new (std::align_val_t (64), x) A;
81 }
82
83
84 A* nowarn_nothrow_Y ()
85 {
86 // Same as above.
87 A *p = new (std::nothrow, y) A;
88 delete p;
89 return new (std::nothrow, y) A;
90 }
91