1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // This test needs to be rewritten for the Windows exception_ptr semantics 11 // which copy the exception each time the exception_ptr is copied. 12 // XFAIL: LIBCXX-WINDOWS-FIXME 13 14 // UNSUPPORTED: libcpp-no-exceptions 15 // <exception> 16 17 // exception_ptr current_exception(); 18 19 #include <exception> 20 #include <cassert> 21 22 struct A 23 { 24 static int constructed; 25 26 A() {++constructed;} 27 ~A() {--constructed;} 28 A(const A&) {++constructed;} 29 }; 30 31 int A::constructed = 0; 32 33 int main() 34 { 35 { 36 std::exception_ptr p = std::current_exception(); 37 assert(p == nullptr); 38 } 39 { 40 try 41 { 42 assert(A::constructed == 0); 43 throw A(); 44 assert(false); 45 } 46 catch (...) 47 { 48 assert(A::constructed == 1); 49 } 50 assert(A::constructed == 0); 51 } 52 assert(A::constructed == 0); 53 { 54 std::exception_ptr p2; 55 try 56 { 57 assert(A::constructed == 0); 58 throw A(); 59 assert(false); 60 } 61 catch (...) 62 { 63 std::exception_ptr p = std::current_exception(); 64 assert(A::constructed == 1); 65 assert(p != nullptr); 66 p2 = std::current_exception(); 67 assert(A::constructed == 1); 68 assert(p == p2); 69 } 70 assert(A::constructed == 1); 71 } 72 assert(A::constructed == 0); 73 { 74 std::exception_ptr p2; 75 try 76 { 77 assert(A::constructed == 0); 78 throw A(); 79 assert(false); 80 } 81 catch (A&) 82 { 83 std::exception_ptr p = std::current_exception(); 84 assert(A::constructed == 1); 85 assert(p != nullptr); 86 p2 = std::current_exception(); 87 assert(A::constructed == 1); 88 assert(p == p2); 89 } 90 assert(A::constructed == 1); 91 } 92 assert(A::constructed == 0); 93 { 94 std::exception_ptr p2; 95 try 96 { 97 assert(A::constructed == 0); 98 throw A(); 99 assert(false); 100 } 101 catch (A) 102 { 103 std::exception_ptr p = std::current_exception(); 104 assert(A::constructed == 2); 105 assert(p != nullptr); 106 p2 = std::current_exception(); 107 assert(A::constructed == 2); 108 assert(p == p2); 109 } 110 assert(A::constructed == 1); 111 } 112 assert(A::constructed == 0); 113 { 114 try 115 { 116 assert(A::constructed == 0); 117 throw A(); 118 assert(false); 119 } 120 catch (...) 121 { 122 assert(A::constructed == 1); 123 try 124 { 125 assert(A::constructed == 1); 126 throw; 127 assert(false); 128 } 129 catch (...) 130 { 131 assert(A::constructed == 1); 132 } 133 assert(A::constructed == 1); 134 } 135 assert(A::constructed == 0); 136 } 137 assert(A::constructed == 0); 138 { 139 try 140 { 141 assert(A::constructed == 0); 142 throw A(); 143 assert(false); 144 } 145 catch (...) 146 { 147 assert(A::constructed == 1); 148 try 149 { 150 std::exception_ptr p = std::current_exception(); 151 assert(A::constructed == 1); 152 assert(p != nullptr); 153 throw; 154 assert(false); 155 } 156 catch (...) 157 { 158 assert(A::constructed == 1); 159 } 160 assert(A::constructed == 1); 161 } 162 assert(A::constructed == 0); 163 } 164 assert(A::constructed == 0); 165 { 166 try 167 { 168 assert(A::constructed == 0); 169 throw A(); 170 assert(false); 171 } 172 catch (...) 173 { 174 assert(A::constructed == 1); 175 try 176 { 177 assert(A::constructed == 1); 178 throw; 179 assert(false); 180 } 181 catch (...) 182 { 183 std::exception_ptr p = std::current_exception(); 184 assert(A::constructed == 1); 185 assert(p != nullptr); 186 } 187 assert(A::constructed == 1); 188 } 189 assert(A::constructed == 0); 190 } 191 assert(A::constructed == 0); 192 { 193 try 194 { 195 assert(A::constructed == 0); 196 throw A(); 197 assert(false); 198 } 199 catch (...) 200 { 201 assert(A::constructed == 1); 202 try 203 { 204 assert(A::constructed == 1); 205 throw; 206 assert(false); 207 } 208 catch (...) 209 { 210 assert(A::constructed == 1); 211 } 212 std::exception_ptr p = std::current_exception(); 213 assert(A::constructed == 1); 214 assert(p != nullptr); 215 } 216 assert(A::constructed == 0); 217 } 218 assert(A::constructed == 0); 219 { 220 try 221 { 222 assert(A::constructed == 0); 223 throw A(); 224 assert(false); 225 } 226 catch (...) 227 { 228 assert(A::constructed == 1); 229 try 230 { 231 assert(A::constructed == 1); 232 throw; 233 assert(false); 234 } 235 catch (...) 236 { 237 assert(A::constructed == 1); 238 } 239 assert(A::constructed == 1); 240 } 241 std::exception_ptr p = std::current_exception(); 242 assert(A::constructed == 0); 243 assert(p == nullptr); 244 } 245 assert(A::constructed == 0); 246 { 247 std::exception_ptr p; 248 try 249 { 250 assert(A::constructed == 0); 251 throw A(); 252 assert(false); 253 } 254 catch (...) 255 { 256 assert(A::constructed == 1); 257 try 258 { 259 assert(A::constructed == 1); 260 throw; 261 assert(false); 262 } 263 catch (...) 264 { 265 p = std::current_exception(); 266 assert(A::constructed == 1); 267 } 268 assert(A::constructed == 1); 269 } 270 assert(A::constructed == 1); 271 assert(p != nullptr); 272 } 273 assert(A::constructed == 0); 274 } 275