Mercurial > hg > CbC > CbC_llvm
comparison libcxxabi/test/test_vector1.pass.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
6 // | 6 // |
7 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
8 | 8 |
9 #include "cxxabi.h" | 9 #include "cxxabi.h" |
10 | 10 |
11 #include <iostream> | 11 #include <cassert> |
12 #include <cstdio> | |
12 #include <cstdlib> | 13 #include <cstdlib> |
13 #include <cassert> | 14 |
15 #include "test_macros.h" | |
14 | 16 |
15 // Wrapper routines | 17 // Wrapper routines |
16 void *my_alloc2 ( size_t sz ) { | 18 void *my_alloc2 ( size_t sz ) { |
17 void *p = std::malloc ( sz ); | 19 void *p = std::malloc ( sz ); |
18 // std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p ); | 20 // std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p ); |
19 return p; | 21 return p; |
20 } | 22 } |
21 | 23 |
22 void my_dealloc2 ( void *p ) { | 24 void my_dealloc2 ( void *p ) { |
23 // std::printf ( "Freeing %lx\n", (unsigned long) p ); | 25 // std::printf ( "Freeing %lx\n", (unsigned long) p ); |
24 std::free ( p ); | 26 std::free ( p ); |
25 } | 27 } |
26 | 28 |
27 void my_dealloc3 ( void *p, size_t ) { | 29 void my_dealloc3 ( void *p, size_t ) { |
28 // std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz ); | 30 // std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz ); |
29 std::free ( p ); | 31 std::free ( p ); |
30 } | 32 } |
31 | 33 |
32 void my_construct ( void * ) { | 34 void my_construct ( void * ) { |
33 // std::printf ( "Constructing %lx\n", (unsigned long) p ); | 35 // std::printf ( "Constructing %lx\n", (unsigned long) p ); |
34 } | 36 } |
35 | 37 |
36 void my_destruct ( void * ) { | 38 void my_destruct ( void * ) { |
37 // std::printf ( "Destructing %lx\n", (unsigned long) p ); | 39 // std::printf ( "Destructing %lx\n", (unsigned long) p ); |
38 } | 40 } |
39 | 41 |
40 int gCounter; | 42 int gCounter; |
41 void count_construct ( void * ) { ++gCounter; } | 43 void count_construct ( void * ) { ++gCounter; } |
42 void count_destruct ( void * ) { --gCounter; } | 44 void count_destruct ( void * ) { --gCounter; } |
43 | 45 |
45 int gConstructorCounter; | 47 int gConstructorCounter; |
46 int gConstructorThrowTarget; | 48 int gConstructorThrowTarget; |
47 int gDestructorCounter; | 49 int gDestructorCounter; |
48 int gDestructorThrowTarget; | 50 int gDestructorThrowTarget; |
49 void throw_construct ( void * ) { | 51 void throw_construct ( void * ) { |
50 #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | 52 #ifndef TEST_HAS_NO_EXCEPTIONS |
51 if ( gConstructorCounter == gConstructorThrowTarget ) | 53 if ( gConstructorCounter == gConstructorThrowTarget ) |
52 throw 1; | 54 throw 1; |
53 ++gConstructorCounter; | 55 ++gConstructorCounter; |
54 #endif | 56 #endif |
55 } | 57 } |
56 void throw_destruct ( void * ) { | 58 void throw_destruct ( void * ) { |
57 #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | 59 #ifndef TEST_HAS_NO_EXCEPTIONS |
58 if ( ++gDestructorCounter == gDestructorThrowTarget ) | 60 if ( ++gDestructorCounter == gDestructorThrowTarget ) |
59 throw 2; | 61 throw 2; |
60 #endif | 62 #endif |
61 } | 63 } |
62 | 64 |
68 | 70 |
69 struct vec_on_stack { | 71 struct vec_on_stack { |
70 void *storage; | 72 void *storage; |
71 vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {} | 73 vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {} |
72 ~vec_on_stack () CAN_THROW {__cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); } | 74 ~vec_on_stack () CAN_THROW {__cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); } |
73 }; | 75 }; |
74 | 76 |
75 // Test calls with empty constructors and destructors | 77 // Test calls with empty constructors and destructors |
76 int test_empty ( ) { | 78 int test_empty ( ) { |
77 void *one, *two, *three; | 79 void *one, *two, *three; |
78 | 80 |
82 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, NULL, NULL, my_alloc2, my_dealloc3 ); | 84 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, NULL, NULL, my_alloc2, my_dealloc3 ); |
83 | 85 |
84 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, NULL ); | 86 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, NULL ); |
85 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, NULL, my_dealloc2 ); | 87 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, NULL, my_dealloc2 ); |
86 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, NULL, my_dealloc3 ); | 88 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, NULL, my_dealloc3 ); |
87 | 89 |
88 // Try with no padding | 90 // Try with no padding |
89 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, my_construct, my_destruct ); | 91 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, my_construct, my_destruct ); |
90 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc2 ); | 92 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc2 ); |
91 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc3 ); | 93 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc3 ); |
92 | 94 |
93 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, my_destruct ); | 95 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, my_destruct ); |
94 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, my_destruct, my_dealloc2 ); | 96 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, my_destruct, my_dealloc2 ); |
95 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, my_destruct, my_dealloc3 ); | 97 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, my_destruct, my_dealloc3 ); |
96 | 98 |
97 // Padding and no con/destructors | 99 // Padding and no con/destructors |
98 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, NULL, NULL ); | 100 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, NULL, NULL ); |
99 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc2 ); | 101 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc2 ); |
100 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc3 ); | 102 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc3 ); |
101 | 103 |
102 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, NULL ); | 104 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, NULL ); |
103 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, NULL, my_dealloc2 ); | 105 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, NULL, my_dealloc2 ); |
104 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, NULL, my_dealloc3 ); | 106 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, NULL, my_dealloc3 ); |
105 | 107 |
106 // Padding with con/destructors | 108 // Padding with con/destructors |
107 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, my_construct, my_destruct ); | 109 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, my_construct, my_destruct ); |
108 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc2 ); | 110 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc2 ); |
109 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc3 ); | 111 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc3 ); |
110 | 112 |
111 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, my_destruct ); | 113 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, my_destruct ); |
112 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, my_destruct, my_dealloc2 ); | 114 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, my_destruct, my_dealloc2 ); |
113 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, my_destruct, my_dealloc3 ); | 115 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, my_destruct, my_dealloc3 ); |
114 | 116 |
115 return 0; | 117 return 0; |
116 } | 118 } |
117 | 119 |
118 // Make sure the constructors and destructors are matched | 120 // Make sure the constructors and destructors are matched |
119 int test_counted ( ) { | 121 int test_counted ( ) { |
120 int retVal = 0; | 122 int retVal = 0; |
121 void *one, *two, *three; | 123 void *one, *two, *three; |
122 | 124 |
123 // Try with no padding | 125 // Try with no padding |
124 gCounter = 0; | 126 gCounter = 0; |
125 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, count_construct, count_destruct ); | 127 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, count_construct, count_destruct ); |
126 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc2 ); | 128 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc2 ); |
127 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc3 ); | 129 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc3 ); |
128 | 130 |
129 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, count_destruct ); | 131 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, count_destruct ); |
130 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, count_destruct, my_dealloc2 ); | 132 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, count_destruct, my_dealloc2 ); |
131 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, count_destruct, my_dealloc3 ); | 133 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, count_destruct, my_dealloc3 ); |
132 | 134 |
133 // Since there was no padding, the # of elements in the array are not stored | 135 // Since there was no padding, the # of elements in the array are not stored |
134 // and the destructors are not called. | 136 // and the destructors are not called. |
135 if ( gCounter != 30 ) { | 137 if ( gCounter != 30 ) { |
136 std::cerr << "Mismatched Constructor/Destructor calls (1)" << std::endl; | 138 std::printf("Mismatched Constructor/Destructor calls (1)\n"); |
137 std::cerr << " Expected 30, got " << gCounter << std::endl; | 139 std::printf(" Expected 30, got %d\n", gCounter); |
138 retVal = 1; | 140 retVal = 1; |
139 } | 141 } |
140 | 142 |
141 gCounter = 0; | 143 gCounter = 0; |
142 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, count_construct, count_destruct ); | 144 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, count_construct, count_destruct ); |
143 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc2 ); | 145 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc2 ); |
144 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc3 ); | 146 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc3 ); |
145 | 147 |
146 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, count_destruct ); | 148 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, count_destruct ); |
147 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, count_destruct, my_dealloc2 ); | 149 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, count_destruct, my_dealloc2 ); |
148 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, count_destruct, my_dealloc3 ); | 150 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, count_destruct, my_dealloc3 ); |
149 | 151 |
150 if ( gCounter != 0 ) { | 152 if ( gCounter != 0 ) { |
151 std::cerr << "Mismatched Constructor/Destructor calls (2)" << std::endl; | 153 std::printf("Mismatched Constructor/Destructor calls (2)\n"); |
152 std::cerr << " Expected 0, got " << gCounter << std::endl; | 154 std::printf(" Expected 0, got %d\n", gCounter); |
153 retVal = 1; | 155 retVal = 1; |
154 } | 156 } |
155 | 157 |
156 return retVal; | 158 return retVal; |
157 } | 159 } |
158 | 160 |
159 #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | 161 #ifndef TEST_HAS_NO_EXCEPTIONS |
160 // Make sure the constructors and destructors are matched | 162 // Make sure the constructors and destructors are matched |
161 int test_exception_in_constructor ( ) { | 163 int test_exception_in_constructor ( ) { |
162 int retVal = 0; | 164 int retVal = 0; |
163 void *one, *two, *three; | 165 void *one, *two, *three; |
164 | 166 |
169 try { | 171 try { |
170 one = two = three = NULL; | 172 one = two = three = NULL; |
171 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, throw_construct, throw_destruct ); | 173 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, throw_construct, throw_destruct ); |
172 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); | 174 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); |
173 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); | 175 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); |
174 } | 176 } |
175 catch ( int i ) {} | 177 catch ( int i ) {} |
176 | 178 |
177 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, throw_destruct ); | 179 __cxxabiv1::__cxa_vec_delete ( one, 40, 0, throw_destruct ); |
178 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, throw_destruct, my_dealloc2 ); | 180 __cxxabiv1::__cxa_vec_delete2( two, 40, 0, throw_destruct, my_dealloc2 ); |
179 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, throw_destruct, my_dealloc3 ); | 181 __cxxabiv1::__cxa_vec_delete3( three, 40, 0, throw_destruct, my_dealloc3 ); |
180 | 182 |
181 // Since there was no padding, the # of elements in the array are not stored | 183 // Since there was no padding, the # of elements in the array are not stored |
182 // and the destructors are not called. | 184 // and the destructors are not called. |
183 // Since we threw after 15 calls to the constructor, we should see 5 calls to | 185 // Since we threw after 15 calls to the constructor, we should see 5 calls to |
184 // the destructor from the partially constructed array. | 186 // the destructor from the partially constructed array. |
185 if ( gConstructorCounter - gDestructorCounter != 10 ) { | 187 if ( gConstructorCounter - gDestructorCounter != 10 ) { |
186 std::cerr << "Mismatched Constructor/Destructor calls (1C)" << std::endl; | 188 std::printf("Mismatched Constructor/Destructor calls (1C)\n"); |
187 std::cerr << gConstructorCounter << " constructors, but " << | 189 std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); |
188 gDestructorCounter << " destructors" << std::endl; | 190 retVal = 1; |
189 retVal = 1; | 191 } |
190 } | 192 |
191 | |
192 gConstructorCounter = gDestructorCounter = 0; | 193 gConstructorCounter = gDestructorCounter = 0; |
193 gConstructorThrowTarget = 15; | 194 gConstructorThrowTarget = 15; |
194 gDestructorThrowTarget = -1; | 195 gDestructorThrowTarget = -1; |
195 try { | 196 try { |
196 one = two = three = NULL; | 197 one = two = three = NULL; |
197 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); | 198 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); |
198 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); | 199 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); |
199 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); | 200 three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); |
200 } | 201 } |
201 catch ( int i ) {} | 202 catch ( int i ) {} |
202 | 203 |
203 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); | 204 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); |
204 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); | 205 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); |
205 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, throw_destruct, my_dealloc3 ); | 206 __cxxabiv1::__cxa_vec_delete3( three, 40, 8, throw_destruct, my_dealloc3 ); |
206 | 207 |
207 if ( gConstructorCounter != gDestructorCounter ) { | 208 if ( gConstructorCounter != gDestructorCounter ) { |
208 std::cerr << "Mismatched Constructor/Destructor calls (2C)" << std::endl; | 209 std::printf("Mismatched Constructor/Destructor calls (2C)\n"); |
209 std::cerr << gConstructorCounter << " constructors, but " << | 210 std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); |
210 gDestructorCounter << " destructors" << std::endl; | 211 retVal = 1; |
211 retVal = 1; | 212 } |
212 } | 213 |
213 | 214 return retVal; |
214 return retVal; | 215 } |
215 } | 216 #endif |
216 #endif | 217 |
217 | 218 #ifndef TEST_HAS_NO_EXCEPTIONS |
218 #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | |
219 // Make sure the constructors and destructors are matched | 219 // Make sure the constructors and destructors are matched |
220 int test_exception_in_destructor ( ) { | 220 int test_exception_in_destructor ( ) { |
221 int retVal = 0; | 221 int retVal = 0; |
222 void *one, *two, *three; | 222 void *one, *two, *three; |
223 one = two = three = NULL; | 223 one = two = three = NULL; |
228 gDestructorThrowTarget = 15; | 228 gDestructorThrowTarget = 15; |
229 try { | 229 try { |
230 one = two = NULL; | 230 one = two = NULL; |
231 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); | 231 one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); |
232 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); | 232 two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); |
233 } | 233 } |
234 catch ( int i ) {} | 234 catch ( int i ) {} |
235 | 235 |
236 try { | 236 try { |
237 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); | 237 __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); |
238 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); | 238 __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); |
239 assert(false); | 239 assert(false); |
240 } | 240 } |
241 catch ( int i ) {} | 241 catch ( int i ) {} |
242 | 242 |
243 // We should have thrown in the middle of cleaning up "two", which means that | 243 // We should have thrown in the middle of cleaning up "two", which means that |
244 // there should be 20 calls to the destructor and the try block should exit | 244 // there should be 20 calls to the destructor and the try block should exit |
245 // before the assertion. | 245 // before the assertion. |
246 if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) { | 246 if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) { |
247 std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl; | 247 std::printf("Unexpected Constructor/Destructor calls (1D)\n"); |
248 std::cerr << "Expected (20, 20), but got (" << gConstructorCounter << ", " << | 248 std::printf("Expected (20, 20), but got (%d, %d)\n", gConstructorCounter, gDestructorCounter); |
249 gDestructorCounter << ")" << std::endl; | 249 retVal = 1; |
250 retVal = 1; | 250 } |
251 } | |
252 | 251 |
253 // Try throwing from a destructor - should be fine. | 252 // Try throwing from a destructor - should be fine. |
254 gConstructorCounter = gDestructorCounter = 0; | 253 gConstructorCounter = gDestructorCounter = 0; |
255 gConstructorThrowTarget = -1; | 254 gConstructorThrowTarget = -1; |
256 gDestructorThrowTarget = 5; | 255 gDestructorThrowTarget = 5; |
257 try { vec_on_stack v; } | 256 try { vec_on_stack v; } |
258 catch ( int i ) {} | 257 catch ( int i ) {} |
259 | 258 |
260 if ( gConstructorCounter != gDestructorCounter ) { | 259 if ( gConstructorCounter != gDestructorCounter ) { |
261 std::cerr << "Mismatched Constructor/Destructor calls (2D)" << std::endl; | 260 std::printf("Mismatched Constructor/Destructor calls (2D)\n"); |
262 std::cerr << gConstructorCounter << " constructors, but " << | 261 std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); |
263 gDestructorCounter << " destructors" << std::endl; | 262 retVal = 1; |
264 retVal = 1; | 263 } |
265 } | 264 |
266 | 265 return retVal; |
267 return retVal; | 266 } |
268 } | 267 #endif |
269 #endif | 268 |
270 | 269 int main(int, char**) { |
271 int main () { | |
272 int retVal = 0; | 270 int retVal = 0; |
273 retVal += test_empty (); | 271 retVal += test_empty (); |
274 retVal += test_counted (); | 272 retVal += test_counted (); |
275 #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | 273 #ifndef TEST_HAS_NO_EXCEPTIONS |
276 retVal += test_exception_in_constructor (); | 274 retVal += test_exception_in_constructor (); |
277 retVal += test_exception_in_destructor (); | 275 retVal += test_exception_in_destructor (); |
278 #endif | 276 #endif |
279 return retVal; | 277 return retVal; |
280 } | 278 } |