Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / expr / expr.unary / expr.new / p20.cpp
blob8cbe2b9be3be72b6c5b251a47a3e7cbecd0f85ba
1 // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions %s
2 typedef __SIZE_TYPE__ size_t;
4 // Overloaded operator delete with two arguments
5 template<int I>
6 struct X0 {
7 X0();
8 static void* operator new(size_t);
9 static void operator delete(void*, size_t) {
10 int *ip = I; // expected-error{{cannot initialize}}
14 void test_X0() {
15 new X0<1>; // expected-note{{instantiation}}
18 // Overloaded operator delete with one argument
19 template<int I>
20 struct X1 {
21 X1();
23 static void* operator new(size_t);
24 static void operator delete(void*) {
25 int *ip = I; // expected-error{{cannot initialize}}
29 void test_X1() {
30 new X1<1>; // expected-note{{instantiation}}
33 // Overloaded operator delete for placement new
34 template<int I>
35 struct X2 {
36 X2();
38 static void* operator new(size_t, double, double);
39 static void* operator new(size_t, int, int);
41 static void operator delete(void*, const int, int) {
42 int *ip = I; // expected-error{{cannot initialize}}
45 static void operator delete(void*, double, double);
48 void test_X2() {
49 new (0, 0) X2<1>; // expected-note{{instantiation}}
52 // Operator delete template for placement new
53 struct X3 {
54 X3();
56 static void* operator new(size_t, double, double);
58 template<typename T>
59 static void operator delete(void*, T x, T) {
60 double *dp = &x;
61 int *ip = &x; // expected-error{{cannot initialize}}
65 void test_X3() {
66 new (0, 0) X3; // expected-note{{instantiation}}
69 // Operator delete template for placement new in global scope.
70 struct X4 {
71 X4();
72 static void* operator new(size_t, double, double);
75 template<typename T>
76 void operator delete(void*, T x, T) {
77 double *dp = &x;
78 int *ip = &x; // expected-error{{cannot initialize}}
81 void test_X4() {
82 new (0, 0) X4; // expected-note{{instantiation}}
85 // Useless operator delete hides global operator delete template.
86 struct X5 {
87 X5();
88 static void* operator new(size_t, double, double);
89 void operator delete(void*, double*, double*);
92 void test_X5() {
93 new (0, 0) X5; // okay, we found X5::operator delete but didn't pick it
96 // Operator delete template for placement new
97 template<int I>
98 struct X6 {
99 X6();
101 static void* operator new(size_t) {
102 return I; // expected-error{{cannot initialize}}
105 static void operator delete(void*) {
106 int *ip = I; // expected-error{{cannot initialize}}
110 void test_X6() {
111 new X6<3>; // expected-note 2{{instantiation}}
114 void *operator new(size_t, double, double, double);
116 template<typename T>
117 void operator delete(void*, T x, T, T) {
118 double *dp = &x;
119 int *ip = &x; // expected-error{{cannot initialize}}
121 void test_int_new() {
122 new (1.0, 1.0, 1.0) int; // expected-note{{instantiation}}
125 // We don't need an operator delete if the type has a trivial
126 // constructor, since we know that constructor cannot throw.
127 // FIXME: Is this within the standard? Seems fishy, but both EDG+GCC do it.
128 #if 0
129 template<int I>
130 struct X7 {
131 static void* operator new(size_t);
132 static void operator delete(void*, size_t) {
133 int *ip = I; // okay, since it isn't instantiated.
137 void test_X7() {
138 new X7<1>;
140 #endif