[libcxx] r177824 - 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.
Howard Hinnant
hhinnant at apple.com
Sat Mar 23 10:27:16 PDT 2013
Author: hhinnant
Date: Sat Mar 23 12:27:16 2013
New Revision: 177824
URL: http://llvm.org/viewvc/llvm-project?rev=177824&view=rev
Log:
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.
Modified:
libcxx/trunk/test/containers/stack_allocator.h
libcxx/trunk/test/containers/test_allocator.h
libcxx/trunk/test/re/test_allocator.h
libcxx/trunk/test/strings/basic.string/test_allocator.h
libcxx/trunk/test/thread/futures/test_allocator.h
libcxx/trunk/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h
libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h
Modified: libcxx/trunk/test/containers/stack_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/stack_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/containers/stack_allocator.h (original)
+++ libcxx/trunk/test/containers/stack_allocator.h Sat Mar 23 12:27:16 2013
@@ -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;
Modified: libcxx/trunk/test/containers/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/containers/test_allocator.h (original)
+++ libcxx/trunk/test/containers/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
}
Modified: libcxx/trunk/test/re/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/re/test_allocator.h (original)
+++ libcxx/trunk/test/re/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
}
Modified: libcxx/trunk/test/strings/basic.string/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/strings/basic.string/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/strings/basic.string/test_allocator.h (original)
+++ libcxx/trunk/test/strings/basic.string/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
}
Modified: libcxx/trunk/test/thread/futures/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/thread/futures/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/thread/futures/test_allocator.h (original)
+++ libcxx/trunk/test/thread/futures/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
}
Modified: libcxx/trunk/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h (original)
+++ libcxx/trunk/test/utilities/function.objects/func.wrap/func.wrap.func/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
}
Modified: libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h?rev=177824&r1=177823&r2=177824&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h (original)
+++ libcxx/trunk/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h Sat Mar 23 12:27:16 2013
@@ -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));
More information about the cfe-commits
mailing list