gcc/testsuite/gdc.test/runnable/eh2.d
raw| 1 | // PERMUTE_ARGS: -fPIC |
| 2 | |
| 3 | extern(C) int printf(const char*, ...); |
| 4 | |
| 5 | class Abc : Throwable |
| 6 | { |
| 7 | this() pure |
| 8 | { |
| 9 | super(""); |
| 10 | } |
| 11 | static int x; |
| 12 | int a,b,c; |
| 13 | |
| 14 | synchronized void test() |
| 15 | { |
| 16 | printf("test 1\n"); |
| 17 | x |= 1; |
| 18 | foo(); |
| 19 | printf("test 2\n"); |
| 20 | x |= 2; |
| 21 | } |
| 22 | |
| 23 | shared void foo() |
| 24 | { |
| 25 | printf("foo 1\n"); |
| 26 | x |= 4; |
| 27 | throw cast() this; |
| 28 | printf("foo 2\n"); |
| 29 | x |= 8; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | struct RefCounted |
| 34 | { |
| 35 | void *p; |
| 36 | ~this() |
| 37 | { |
| 38 | p = null; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | struct S |
| 43 | { |
| 44 | RefCounted _data; |
| 45 | |
| 46 | int get() @property |
| 47 | { |
| 48 | throw new Exception(""); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void b9438() |
| 53 | { |
| 54 | try |
| 55 | { |
| 56 | S s; |
| 57 | S().get; |
| 58 | } |
| 59 | catch (Exception e){ } |
| 60 | } |
| 61 | |
| 62 | int main() |
| 63 | { |
| 64 | printf("hello world\n"); |
| 65 | auto a = new shared(Abc)(); |
| 66 | printf("hello 2\n"); |
| 67 | Abc.x |= 0x10; |
| 68 | |
| 69 | try |
| 70 | { |
| 71 | Abc.x |= 0x20; |
| 72 | a.test(); |
| 73 | Abc.x |= 0x40; |
| 74 | } |
| 75 | catch (Abc b) |
| 76 | { |
| 77 | Abc.x |= 0x80; |
| 78 | printf("Caught %p, x = x%x\n", b, Abc.x); |
| 79 | assert(cast() a is b); |
| 80 | assert(Abc.x == 0xB5); |
| 81 | } |
| 82 | printf("Success!\n"); |
| 83 | b9438(); |
| 84 | return 0; |
| 85 | } |