summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Chisnall <dchisnall@pathscale.com>2012-03-20 16:56:14 +0000
committerDavid Chisnall <dchisnall@pathscale.com>2012-03-20 16:56:14 +0000
commitcddcf8734ed06ada9384a461bc21d58b44f6eba1 (patch)
tree05f0ee42205622cb4851edc2dcce576708f68739 /test
parenta35d8de85ffd4df32e2dc47fa539d61fd3024a54 (diff)
downloadlibcxxrt-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')
-rw-r--r--test/test_exception.cc36
-rw-r--r--test/test_typeinfo.cc3
2 files changed, 36 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",
diff --git a/test/test_typeinfo.cc b/test/test_typeinfo.cc
index 6d2fbdd..9fc8ef7 100644
--- a/test/test_typeinfo.cc
+++ b/test/test_typeinfo.cc
@@ -79,6 +79,7 @@ void test_type_info(void)
Root *b2 = &root;
Root *v1 = &virt1;
Virt1 *d1 = &diamond;
+ Root *up = &diamond;
b->test = 12;
f->test = 12;
b2->test = 12;
@@ -103,6 +104,8 @@ void test_type_info(void)
d2->test = 12;
TEST(12 == dynamic_cast<Diamond2*>(d2)->test, "Casting Diamond2 to Diamond2");
TEST(12 == dynamic_cast<Virt2a*>(d2)->test, "Casting Diamond2 to Virt2a");
+ TEST(&diamond == dynamic_cast<Diamond*>(up), "Downcasting root-pointer to diamond");
+ TEST(0 == dynamic_cast<Diamond*>(&root), "Downcasting root to diamond");
TEST(0 == dynamic_cast<Sub1*>(b2), "Casting Root to Sub1 (0 expected)");
}