From cddcf8734ed06ada9384a461bc21d58b44f6eba1 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Tue, 20 Mar 2012 16:56:14 +0000 Subject: 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 . 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. --- test/test_exception.cc | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'test/test_exception.cc') 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", -- cgit v1.2.3