From 9976b5511a5ff7c67dc7bc024604efa0baf43625 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 23 Mar 2013 17:27:16 +0000 Subject: [PATCH] This is a start at making the libc++ test suite friendlier to the -fnoexceptions flag. Although this is not a complete solution, it does reduce the number of test failures on OS X from 467 to 128 on OS X when -fno-exceptions is enabled, and does not impact the number of failures at all when -fno-exceptions is not enabled. The bulk of this code was donated anonymously. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@177824 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/containers/stack_allocator.h | 7 ++++++- test/containers/test_allocator.h | 7 ++++++- test/re/test_allocator.h | 7 ++++++- test/strings/basic.string/test_allocator.h | 7 ++++++- test/thread/futures/test_allocator.h | 7 ++++++- .../func.wrap/func.wrap.func/test_allocator.h | 7 ++++++- .../util.smartptr/util.smartptr.shared/test_allocator.h | 7 ++++++- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/test/containers/stack_allocator.h b/test/containers/stack_allocator.h index 30f58718e..e6af47381 100644 --- a/test/containers/stack_allocator.h +++ b/test/containers/stack_allocator.h @@ -29,8 +29,13 @@ private: public: pointer allocate(size_type n, const void* = 0) { - if (n > N - (ptr_ - buf_) / sizeof(value_type)) + if (n > N - (ptr_ - buf_) / sizeof(value_type)) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } pointer r = (T*)ptr_; ptr_ += n * sizeof(T); return r; diff --git a/test/containers/test_allocator.h b/test/containers/test_allocator.h index c5da7e639..eed33a0e3 100644 --- a/test/containers/test_allocator.h +++ b/test/containers/test_allocator.h @@ -48,8 +48,13 @@ public: const_pointer address(const_reference x) const {return &x;} pointer allocate(size_type n, const void* = 0) { - if (count >= throw_after) + if (count >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++count; return (pointer)std::malloc(n * sizeof(T)); } diff --git a/test/re/test_allocator.h b/test/re/test_allocator.h index c5da7e639..eed33a0e3 100644 --- a/test/re/test_allocator.h +++ b/test/re/test_allocator.h @@ -48,8 +48,13 @@ public: const_pointer address(const_reference x) const {return &x;} pointer allocate(size_type n, const void* = 0) { - if (count >= throw_after) + if (count >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++count; return (pointer)std::malloc(n * sizeof(T)); } diff --git a/test/strings/basic.string/test_allocator.h b/test/strings/basic.string/test_allocator.h index 001ca98bd..89852159d 100644 --- a/test/strings/basic.string/test_allocator.h +++ b/test/strings/basic.string/test_allocator.h @@ -48,8 +48,13 @@ public: const_pointer address(const_reference x) const {return &x;} pointer allocate(size_type n, const void* = 0) { - if (count >= throw_after) + if (count >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++count; return (pointer)std::malloc(n * sizeof(T)); } diff --git a/test/thread/futures/test_allocator.h b/test/thread/futures/test_allocator.h index 7644bc7c9..e04d43206 100644 --- a/test/thread/futures/test_allocator.h +++ b/test/thread/futures/test_allocator.h @@ -48,8 +48,13 @@ public: const_pointer address(const_reference x) const {return &x;} pointer allocate(size_type n, const void* = 0) { - if (count >= throw_after) + if (count >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++count; return (pointer)std::malloc(n * sizeof(T)); } diff --git a/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h b/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h index c5da7e639..eed33a0e3 100644 --- a/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h +++ b/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h @@ -48,8 +48,13 @@ public: const_pointer address(const_reference x) const {return &x;} pointer allocate(size_type n, const void* = 0) { - if (count >= throw_after) + if (count >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++count; return (pointer)std::malloc(n * sizeof(T)); } diff --git a/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h b/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h index 795f6e1f7..d9b72bce4 100644 --- a/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h +++ b/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h @@ -54,8 +54,13 @@ public: pointer allocate(size_type n, const void* = 0) { assert(data_ >= 0); - if (time_to_throw >= throw_after) + if (time_to_throw >= throw_after) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + std::terminate(); +#endif + } ++time_to_throw; ++alloc_count; return (pointer)std::malloc(n * sizeof(T));