diff options
author | David Chisnall <dchisnall@pathscale.com> | 2012-03-20 16:56:14 +0000 |
---|---|---|
committer | David Chisnall <dchisnall@pathscale.com> | 2012-03-20 16:56:14 +0000 |
commit | cddcf8734ed06ada9384a461bc21d58b44f6eba1 (patch) | |
tree | 05f0ee42205622cb4851edc2dcce576708f68739 /test/test_exception.cc | |
parent | a35d8de85ffd4df32e2dc47fa539d61fd3024a54 (diff) | |
download | libcxxrt-cddcf8734ed06ada9384a461bc21d58b44f6eba1.tar.gz libcxxrt-cddcf8734ed06ada9384a461bc21d58b44f6eba1.tar.bz2 libcxxrt-cddcf8734ed06ada9384a461bc21d58b44f6eba1.tar.xz |
Rework exception matching.
- Remove typeinfo since thing break if the compiler decides to use the
system one and merge its contents into typeinfo.h
- Make each type_info object have a vtable with the same layout as the
public vtable in libstdc++'s <typeinfo>. This fixes code (e.g.
libobjc2's Objective-C++ exception handling) which rely on being able
to add new types.
- Add some extra tests
I suspect exceptions catching pointer-to-member types will not work
correctly, but I've never seen anyone do this and don't have any tests
for it.
Diffstat (limited to 'test/test_exception.cc')
-rw-r--r-- | test/test_exception.cc | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/test/test_exception.cc b/test/test_exception.cc index 6e16ca9..0685329 100644 --- a/test/test_exception.cc +++ b/test/test_exception.cc @@ -9,7 +9,7 @@ void log(void* ignored) { - printf("Cleanup called on %s\n", *(char**)ignored); + //printf("Cleanup called on %s\n", *(char**)ignored); } #define CLEANUP\ __attribute__((cleanup(log))) __attribute__((unused))\ @@ -81,6 +81,35 @@ int outer(int i) throw(float, int, foo, non_pod) return 1; } +static void test_const(void) +{ + int a = 1; + try + { + throw a; + } + catch (const int b) + { + TEST(a == b, "Caught int as const int"); + } + catch(...) + { + TEST(0, "Failed to catch int as const int"); + } + try + { + throw &a; + } + catch (const int *b) + { + TEST(&a == b, "Caught int* as const int*"); + } + catch(...) + { + TEST(0, "Failed to catch int* as const int*"); + } +} + static void test_catch(int s) { cl c; @@ -92,7 +121,7 @@ static void test_catch(int s) } catch(int i) { - fprintf(stderr, "Caught int %d!\n", i); + fprintf(stderr, "Caught int %d in test %d\n", i, s); TEST((s == 0 && i == 1) || (s == 2 && i == 0), "Caught int"); return; } @@ -158,7 +187,7 @@ static int violations = 0; static void throw_zero() { violations++; -fprintf(stderr, "Throwing 0\n"); + fprintf(stderr, "Throwing 0\n"); throw 0; } @@ -207,6 +236,7 @@ void test_exceptions(void) { TEST(0, "Bad cast was not caught correctly"); } + test_const(); //printf("Test: %s\n", |