[libcxx] r268842 - Change allocator<T>::allocate to throw length_error, not bad_alloc
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Fri May 6 20:12:25 PDT 2016
Author: ericwf
Date: Fri May 6 22:12:24 2016
New Revision: 268842
URL: http://llvm.org/viewvc/llvm-project?rev=268842&view=rev
Log:
Change allocator<T>::allocate to throw length_error, not bad_alloc
Modified:
libcxx/trunk/include/memory
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=268842&r1=268841&r2=268842&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Fri May 6 22:12:24 2016
@@ -607,6 +607,7 @@ void* align(size_t alignment, size_t siz
#include <__functional_base>
#include <iosfwd>
#include <tuple>
+#include <stdexcept>
#include <cstring>
#if defined(_LIBCPP_NO_EXCEPTIONS)
#include <cassert>
@@ -1728,11 +1729,8 @@ public:
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
{
if (__n > max_size())
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw bad_alloc();
-#else
- assert(!"allocator<T>::allocate::bad_alloc");
-#endif
+ __libcpp_throw(length_error("allocator<T>::allocate(size_t n)"
+ " 'n' exceeds maximum supported size"));
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
}
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
@@ -1827,13 +1825,10 @@ public:
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
{
if (__n > max_size())
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw bad_alloc();
-#else
- assert(!"allocator<const T>::allocate::bad_alloc");
-#endif
+ __libcpp_throw(length_error("allocator<const T>::allocate(size_t n)"
+ " 'n' exceeds maximum supported size"));
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
- }
+ }
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
{_VSTD::__deallocate((void*)__p);}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
Modified: libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp?rev=268842&r1=268841&r2=268842&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp Fri May 6 22:12:24 2016
@@ -20,9 +20,11 @@ template <typename T>
void test_max(size_t count)
{
std::allocator<T> a;
- try { a.allocate( count ); }
- catch ( const std::bad_alloc &) { return ; }
- assert (false);
+ try {
+ a.allocate(count);
+ assert(false);
+ } catch (const std::exception &) {
+ }
}
int main()
More information about the cfe-commits
mailing list