aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2000-06-06 16:39:52 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2000-06-06 16:39:52 +0000
commitb6a5dfa1cf54076f29e58bf6455bb59af75f5e6a (patch)
tree518b9fa5d1a7fb16fd9c5e830cd1818ff9140deb
parent103c63aeb9b6bb856ff8a34b7e35d0dc7ab9bf83 (diff)
downloadgcc-b6a5dfa1cf54076f29e58bf6455bb59af75f5e6a.zip
gcc-b6a5dfa1cf54076f29e58bf6455bb59af75f5e6a.tar.gz
gcc-b6a5dfa1cf54076f29e58bf6455bb59af75f5e6a.tar.bz2
* g++.old-deja/g++.eh/badalloc1.C: New test.
From-SVN: r34430
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C77
2 files changed, 81 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b3ac079..db0f3cf 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2000-06-06 Nathan Sidwell <nathan@codesourcery.com>
+
+ * g++.old-deja/g++.eh/badalloc1.C: New test.
+
2000-06-05 Richard Henderson <rth@cygnus.com>
* gcc.c-torture/execute/20000605-1.c: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C
new file mode 100644
index 0000000..05de379
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C
@@ -0,0 +1,77 @@
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com>
+
+// Check we can throw a bad_alloc exception when malloc dies
+
+static __SIZE_TYPE__ arena[100000]; // so things can initialize
+static int fail;
+static unsigned pos;
+
+extern "C" void *malloc (__SIZE_TYPE__ size)
+{
+ unsigned *p = &arena[pos];
+
+ if (fail)
+ return 0;
+
+ arena[pos] = size;
+ size = (size + 4 * sizeof (__SIZE_TYPE__) - 1)
+ / sizeof (__SIZE_TYPE__) & ~3; // Yes, this is a hack
+ pos += size + 4;
+ return p + 4;
+}
+extern "C" void free (void *)
+{
+
+}
+extern "C" void *realloc (void *p, __SIZE_TYPE__ size)
+{
+ void *r = malloc (size);
+ unsigned int oldSize;
+
+ if (r && p)
+ {
+ oldSize = ((__SIZE_TYPE__ *)p)[-4];
+ if (oldSize < size)
+ size = oldSize;
+ while (size--)
+ ((char *)r)[size] = ((char *)p)[size];
+ }
+ free (p);
+ return r;
+}
+
+void fn_throw() throw(int)
+{
+ throw 1;
+}
+
+void fn_rethrow() throw(int)
+{
+ try{fn_throw();}
+ catch(int a){
+ throw;}
+}
+
+void fn_catchthrow() throw(int)
+{
+ try{fn_throw();}
+ catch(int a){
+ throw a + 1;}
+}
+
+int main()
+{
+ fail = 1;
+
+ try{fn_throw();}
+ catch(int a){}
+
+ try{fn_rethrow();}
+ catch(int a){}
+
+ try{fn_catchthrow();}
+ catch(int a){}
+
+ return 0;
+}