Howard Hinnant | 372e2f4 | 2012-01-31 23:52:20 +0000 | [diff] [blame] | 1 | //===---------------------- catch_class_01.cpp ----------------------------===// |
| 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 | #include <exception> |
| 11 | #include <stdlib.h> |
| 12 | #include <assert.h> |
| 13 | |
| 14 | struct A |
| 15 | { |
| 16 | static int count; |
| 17 | int id_; |
| 18 | explicit A(int id) : id_(id) {count++;} |
| 19 | A(const A& a) : id_(a.id_) {count++;} |
| 20 | ~A() {count--;} |
| 21 | }; |
| 22 | |
| 23 | int A::count = 0; |
| 24 | |
| 25 | void f1() |
| 26 | { |
| 27 | throw A(3); |
| 28 | } |
| 29 | |
| 30 | void f2() |
| 31 | { |
| 32 | try |
| 33 | { |
| 34 | assert(A::count == 0); |
| 35 | f1(); |
| 36 | } |
| 37 | catch (A a) |
| 38 | { |
| 39 | assert(A::count != 0); |
| 40 | assert(a.id_ == 3); |
| 41 | throw; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | try |
| 48 | { |
| 49 | f2(); |
| 50 | assert(false); |
| 51 | } |
| 52 | catch (const A& a) |
| 53 | { |
| 54 | assert(A::count != 0); |
| 55 | assert(a.id_ == 3); |
| 56 | } |
| 57 | assert(A::count == 0); |
| 58 | } |