Add an _LIBCPP_NORETURN inline function named __throw_XXX for each exception type we define. They either construct and throw the exception, or abort() (if exceptions are disabled). Use these functions everywhere instead of assert()ing when exceptions are disabled. WARNING: This is a behavior change - but only with exceptions disabled. Reviewed as: https://reviews.llvm.org/D23855.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@279744 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -82,7 +82,6 @@ inline namespace fundamentals_v1 {
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
@@ -98,13 +97,13 @@ public:
|
||||
|
||||
#if _LIBCPP_STD_VER > 11 // C++ > 11
|
||||
|
||||
_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
|
||||
inline void __throw_bad_any_cast()
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_any_cast();
|
||||
#else
|
||||
assert(!"bad_any_cast");
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -106,10 +106,6 @@ public:
|
||||
|
||||
#include <__undef___deallocate>
|
||||
|
||||
#if defined(_LIBCPP_NO_EXCEPTIONS)
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
@@ -142,13 +138,8 @@ private:
|
||||
static inline _LIBCPP_INLINE_VISIBILITY value_type* __allocate ( size_t count )
|
||||
{
|
||||
if ( numeric_limits<size_t>::max() / sizeof (value_type) <= count )
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_array_length();
|
||||
#else
|
||||
assert(!"dynarray::allocation");
|
||||
#endif
|
||||
}
|
||||
__throw_bad_array_length();
|
||||
|
||||
return static_cast<value_type *> (_VSTD::__allocate (sizeof(value_type) * count));
|
||||
}
|
||||
|
||||
@@ -283,13 +274,8 @@ typename dynarray<_Tp>::reference
|
||||
dynarray<_Tp>::at(size_type __n)
|
||||
{
|
||||
if (__n >= __size_)
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw out_of_range("dynarray::at");
|
||||
#else
|
||||
assert(!"dynarray::at out_of_range");
|
||||
#endif
|
||||
}
|
||||
__throw_out_of_range("dynarray::at");
|
||||
|
||||
return data()[__n];
|
||||
}
|
||||
|
||||
@@ -299,13 +285,8 @@ typename dynarray<_Tp>::const_reference
|
||||
dynarray<_Tp>::at(size_type __n) const
|
||||
{
|
||||
if (__n >= __size_)
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw out_of_range("dynarray::at");
|
||||
#else
|
||||
assert(!"dynarray::at out_of_range");
|
||||
#endif
|
||||
}
|
||||
__throw_out_of_range("dynarray::at");
|
||||
|
||||
return data()[__n];
|
||||
}
|
||||
|
||||
|
||||
@@ -513,15 +513,21 @@ public:
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
constexpr explicit operator bool() const noexcept {return this->__engaged_;}
|
||||
|
||||
_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY
|
||||
constexpr void __throw_bad_optional_access() const
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_optional_access();
|
||||
#else
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
constexpr value_type const& value() const
|
||||
{
|
||||
if (!this->__engaged_)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_optional_access();
|
||||
#else
|
||||
assert(!"bad optional access");
|
||||
#endif
|
||||
__throw_bad_optional_access();
|
||||
return this->__val_;
|
||||
}
|
||||
|
||||
@@ -529,11 +535,7 @@ public:
|
||||
value_type& value()
|
||||
{
|
||||
if (!this->__engaged_)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_optional_access();
|
||||
#else
|
||||
assert(!"bad optional access");
|
||||
#endif
|
||||
__throw_bad_optional_access();
|
||||
return this->__val_;
|
||||
}
|
||||
|
||||
|
||||
@@ -362,11 +362,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
|
||||
basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
|
||||
{
|
||||
// if (__pos > size())
|
||||
// throw out_of_range("string_view::substr");
|
||||
// __throw_out_of_range("string_view::substr");
|
||||
// size_type __rlen = _VSTD::min( __n, size() - __pos );
|
||||
// return basic_string_view(data() + __pos, __rlen);
|
||||
return __pos > size()
|
||||
? (__libcpp_throw((out_of_range("string_view::substr"))), basic_string_view())
|
||||
? (__throw_out_of_range("string_view::substr"), basic_string_view())
|
||||
: basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user