summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-01 10:09:40 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-01 10:09:40 +0000
commitf9ca8b77ffddc3323e44e521a3ac31d3dc515c52 (patch)
treeee33ea2741f0a470133a6d3aaf97e5dd0337bd6f /libstdc++-v3/testsuite
parentca2e246e7b95cbd28b244310d4b84201054d7491 (diff)
downloadgcc-f9ca8b77ffddc3323e44e521a3ac31d3dc515c52.tar.gz
2007-06-01 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/throw_allocator.h (__throw_allocator::allocate): Throw bad_alloc for out of memory conditions. * testsuite/ext/throw_allocator/deallocate_global.cc: New. * testsuite/ext/throw_allocator/check_delete.cc: Same. * testsuite/ext/throw_allocator/check_allocate_max_size.cc: Same. * testsuite/ext/throw_allocator/check_deallocate_null.cc: Same. * testsuite/ext/throw_allocator/explicit_instantiation.cc: Same. * testsuite/ext/throw_allocator/check_new.cc: Same. * testsuite/ext/throw_allocator/deallocate_local.cc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125261 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/check_allocate_max_size.cc29
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/check_deallocate_null.cc36
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc54
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc54
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc73
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc64
-rw-r--r--libstdc++-v3/testsuite/ext/throw_allocator/explicit_instantiation.cc25
7 files changed, 335 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_allocate_max_size.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_allocate_max_size.cc
new file mode 100644
index 00000000000..902361eff0d
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_allocate_max_size.cc
@@ -0,0 +1,29 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <ext/throw_allocator.h>
+#include <testsuite_allocator.h>
+
+int main()
+{
+ typedef int value_type;
+ typedef __gnu_cxx::throw_allocator<value_type> allocator_type;
+ __gnu_test::check_allocate_max_size<allocator_type>();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_deallocate_null.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_deallocate_null.cc
new file mode 100644
index 00000000000..8e6e1a025aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_deallocate_null.cc
@@ -0,0 +1,36 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <ext/throw_allocator.h>
+#include <testsuite_allocator.h>
+
+int main()
+{
+ typedef int value_type;
+ typedef __gnu_cxx::throw_allocator<value_type> allocator_type;
+
+ try { __gnu_test::check_deallocate_null<allocator_type>(); }
+ catch (std::logic_error&)
+ {
+ // Should throw logic_error to catch null erase.
+ }
+
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc
new file mode 100644
index 00000000000..a8e716798fe
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <cstdlib>
+#include <ext/throw_allocator.h>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+using __gnu_cxx::throw_allocator;
+
+void*
+operator new(std::size_t n) throw(std::bad_alloc)
+{
+ new_called = true;
+ return std::malloc(n);
+}
+
+void
+operator delete(void *v) throw()
+{
+ delete_called = true;
+ return std::free(v);
+}
+
+// These just help tracking down error messages.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ typedef throw_allocator<unsigned int> allocator_type;
+ VERIFY( bool(__gnu_test::check_delete<allocator_type, true>()) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc
new file mode 100644
index 00000000000..1b00412918f
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <cstdlib>
+#include <ext/throw_allocator.h>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+using __gnu_cxx::throw_allocator;
+
+void*
+operator new(std::size_t n) throw(std::bad_alloc)
+{
+ new_called = true;
+ return std::malloc(n);
+}
+
+void
+operator delete(void *v) throw()
+{
+ delete_called = true;
+ return std::free(v);
+}
+
+// These just help tracking down error messages.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ typedef throw_allocator<unsigned int> allocator_type;
+ VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc
new file mode 100644
index 00000000000..c8bbe510c9b
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc
@@ -0,0 +1,73 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <string>
+#include <stdexcept>
+#include <ext/throw_allocator.h>
+#include <testsuite_hooks.h>
+
+static size_t count;
+
+struct count_check
+{
+ count_check() {}
+ ~count_check()
+ {
+ if (count != 0)
+ throw std::runtime_error("count isn't zero");
+ }
+};
+
+static count_check check;
+
+void* operator new(size_t size) throw(std::bad_alloc)
+{
+ printf("operator new is called \n");
+ void* p = malloc(size);
+ if (p == NULL)
+ throw std::bad_alloc();
+ count++;
+ return p;
+}
+
+void operator delete(void* p) throw()
+{
+ printf("operator delete is called \n");
+ if (p == NULL)
+ return;
+ count--;
+ if (count == 0)
+ printf("All memory released \n");
+ else
+ printf("%lu allocations to be released \n",
+ static_cast<unsigned long>(count));
+ free(p);
+}
+
+typedef char char_t;
+typedef std::char_traits<char_t> traits_t;
+typedef __gnu_cxx::throw_allocator<char_t> allocator_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+
+string_t s("bayou bend");
+
+int main()
+{
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
new file mode 100644
index 00000000000..794232e914e
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
@@ -0,0 +1,64 @@
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <string>
+#include <ext/throw_allocator.h>
+#include <testsuite_hooks.h>
+
+static size_t alloc_cnt;
+
+void* operator new(size_t size) throw(std::bad_alloc)
+{
+ printf("operator new is called \n");
+ void* p = malloc(size);
+ if (p == NULL)
+ throw std::bad_alloc();
+ alloc_cnt++;
+ return p;
+}
+
+void operator delete(void* p) throw()
+{
+ printf("operator delete is called \n");
+ if (p == NULL)
+ return;
+ alloc_cnt--;
+ if (alloc_cnt == 0)
+ printf("All memory released \n");
+ else
+ printf("%lu allocations to be released \n",
+ static_cast<unsigned long>(alloc_cnt));
+ free(p);
+}
+
+typedef char char_t;
+typedef std::char_traits<char_t> traits_t;
+typedef __gnu_cxx::throw_allocator<char_t> allocator_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+
+int main()
+{
+ bool test __attribute__((unused)) = true;
+ {
+ string_t s;
+ s += "bayou bend";
+ }
+ VERIFY( alloc_cnt == 0 );
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/explicit_instantiation.cc b/libstdc++-v3/testsuite/ext/throw_allocator/explicit_instantiation.cc
new file mode 100644
index 00000000000..2ef7d3a9303
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/explicit_instantiation.cc
@@ -0,0 +1,25 @@
+// { dg-do compile }
+
+//
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <cstdlib>
+#include <ext/throw_allocator.h>
+
+template class __gnu_cxx::throw_allocator<int>;