Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 1 | //===---------------------- catch_class_01.cpp ----------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Louis Dionne | 8c61114 | 2020-04-17 10:29:15 -0400 | [diff] [blame] | 9 | // UNSUPPORTED: no-exceptions |
Asiri Rathnayake | 57e446d | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 10 | |
Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 11 | #include <exception> |
| 12 | #include <stdlib.h> |
| 13 | #include <assert.h> |
| 14 | |
| 15 | struct A |
| 16 | { |
| 17 | static int count; |
| 18 | int id_; |
| 19 | explicit A(int id) : id_(id) {count++;} |
| 20 | A(const A& a) : id_(a.id_) {count++;} |
| 21 | ~A() {count--;} |
| 22 | }; |
| 23 | |
| 24 | int A::count = 0; |
| 25 | |
| 26 | void f1() |
| 27 | { |
| 28 | throw A(3); |
| 29 | } |
| 30 | |
| 31 | void f2() |
| 32 | { |
| 33 | try |
| 34 | { |
| 35 | assert(A::count == 0); |
| 36 | f1(); |
| 37 | } |
| 38 | catch (A a) |
| 39 | { |
| 40 | assert(A::count != 0); |
| 41 | assert(a.id_ == 3); |
| 42 | throw; |
| 43 | } |
| 44 | } |
| 45 | |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 46 | int main(int, char**) |
Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 47 | { |
| 48 | try |
| 49 | { |
| 50 | f2(); |
| 51 | assert(false); |
| 52 | } |
| 53 | catch (const A& a) |
| 54 | { |
| 55 | assert(A::count != 0); |
| 56 | assert(a.id_ == 3); |
| 57 | } |
| 58 | assert(A::count == 0); |
Louis Dionne | 504bc07 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 59 | |
| 60 | return 0; |
Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 61 | } |