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:
@@ -152,11 +152,8 @@ __libcpp_db::__insert_c(void* __c)
|
||||
size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
|
||||
__c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*)));
|
||||
if (cbeg == nullptr)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
|
||||
for (__c_node** p = __cbeg_; p != __cend_; ++p)
|
||||
{
|
||||
__c_node* q = *p;
|
||||
@@ -178,11 +175,8 @@ __libcpp_db::__insert_c(void* __c)
|
||||
__c_node* r = __cbeg_[hc] =
|
||||
static_cast<__c_node*>(malloc(sizeof(__c_node)));
|
||||
if (__cbeg_[hc] == nullptr)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
|
||||
r->__c_ = __c;
|
||||
r->__next_ = p;
|
||||
++__csz_;
|
||||
@@ -475,11 +469,8 @@ __c_node::__add(__i_node* i)
|
||||
__i_node** beg =
|
||||
static_cast<__i_node**>(malloc(nc * sizeof(__i_node*)));
|
||||
if (beg == nullptr)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
|
||||
if (nc > 1)
|
||||
memcpy(beg, beg_, nc/2*sizeof(__i_node*));
|
||||
free(beg_);
|
||||
@@ -501,11 +492,8 @@ __libcpp_db::__insert_iterator(void* __i)
|
||||
size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
|
||||
__i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*)));
|
||||
if (ibeg == nullptr)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
|
||||
for (__i_node** p = __ibeg_; p != __iend_; ++p)
|
||||
{
|
||||
__i_node* q = *p;
|
||||
@@ -527,11 +515,8 @@ __libcpp_db::__insert_iterator(void* __i)
|
||||
__i_node* r = __ibeg_[hi] =
|
||||
static_cast<__i_node*>(malloc(sizeof(__i_node)));
|
||||
if (r == nullptr)
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
|
||||
::new(r) __i_node(__i, p, nullptr);
|
||||
++__isz_;
|
||||
return r;
|
||||
|
||||
@@ -50,11 +50,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void* do_allocate(size_t, size_t) {
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw std::bad_alloc();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
__throw_bad_alloc();
|
||||
}
|
||||
virtual void do_deallocate(void *, size_t, size_t) {}
|
||||
virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
|
||||
|
||||
@@ -107,6 +107,16 @@ countof(const T * const begin, const T * const end)
|
||||
return static_cast<size_t>(end - begin);
|
||||
}
|
||||
|
||||
_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw runtime_error(msg);
|
||||
#else
|
||||
(void)msg;
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if defined(_AIX)
|
||||
@@ -646,22 +656,18 @@ collate_byname<char>::collate_byname(const char* n, size_t refs)
|
||||
: collate<char>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, n, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("collate_byname<char>::collate_byname"
|
||||
__throw_runtime_error("collate_byname<char>::collate_byname"
|
||||
" failed to construct for " + string(n));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
collate_byname<char>::collate_byname(const string& name, size_t refs)
|
||||
: collate<char>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("collate_byname<char>::collate_byname"
|
||||
__throw_runtime_error("collate_byname<char>::collate_byname"
|
||||
" failed to construct for " + name);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
collate_byname<char>::~collate_byname()
|
||||
@@ -698,22 +704,18 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
|
||||
: collate<wchar_t>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, n, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
|
||||
__throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
|
||||
" failed to construct for " + string(n));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
|
||||
: collate<wchar_t>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
|
||||
__throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
|
||||
" failed to construct for " + name);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
collate_byname<wchar_t>::~collate_byname()
|
||||
@@ -1172,22 +1174,18 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs)
|
||||
: ctype<char>(0, false, refs),
|
||||
__l(newlocale(LC_ALL_MASK, name, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("ctype_byname<char>::ctype_byname"
|
||||
__throw_runtime_error("ctype_byname<char>::ctype_byname"
|
||||
" failed to construct for " + string(name));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
ctype_byname<char>::ctype_byname(const string& name, size_t refs)
|
||||
: ctype<char>(0, false, refs),
|
||||
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("ctype_byname<char>::ctype_byname"
|
||||
__throw_runtime_error("ctype_byname<char>::ctype_byname"
|
||||
" failed to construct for " + name);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
ctype_byname<char>::~ctype_byname()
|
||||
@@ -1229,22 +1227,18 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
|
||||
: ctype<wchar_t>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, name, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
|
||||
__throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
|
||||
" failed to construct for " + string(name));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
|
||||
: ctype<wchar_t>(refs),
|
||||
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
|
||||
__throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
|
||||
" failed to construct for " + name);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
ctype_byname<wchar_t>::~ctype_byname()
|
||||
@@ -1504,11 +1498,9 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
|
||||
: locale::facet(refs),
|
||||
__l(newlocale(LC_ALL_MASK, nm, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__l == 0)
|
||||
throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
|
||||
__throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
codecvt<wchar_t, char, mbstate_t>::~codecvt()
|
||||
@@ -4257,11 +4249,10 @@ numpunct_byname<char>::__init(const char* nm)
|
||||
if (strcmp(nm, "C") != 0)
|
||||
{
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("numpunct_byname<char>::numpunct_byname"
|
||||
__throw_runtime_error("numpunct_byname<char>::numpunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->decimal_point)
|
||||
__decimal_point_ = *lc->decimal_point;
|
||||
@@ -4296,11 +4287,10 @@ numpunct_byname<wchar_t>::__init(const char* nm)
|
||||
if (strcmp(nm, "C") != 0)
|
||||
{
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("numpunct_byname<char>::numpunct_byname"
|
||||
__throw_runtime_error("numpunct_byname<char>::numpunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->decimal_point)
|
||||
__decimal_point_ = *lc->decimal_point;
|
||||
@@ -4703,21 +4693,17 @@ __time_get_c_storage<wchar_t>::__r() const
|
||||
__time_get::__time_get(const char* nm)
|
||||
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__loc_ == 0)
|
||||
throw runtime_error("time_get_byname"
|
||||
__throw_runtime_error("time_get_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
__time_get::__time_get(const string& nm)
|
||||
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__loc_ == 0)
|
||||
throw runtime_error("time_get_byname"
|
||||
__throw_runtime_error("time_get_byname"
|
||||
" failed to construct for " + nm);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
__time_get::~__time_get()
|
||||
@@ -5363,21 +5349,17 @@ __time_get_storage<wchar_t>::__do_date_order() const
|
||||
__time_put::__time_put(const char* nm)
|
||||
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__loc_ == 0)
|
||||
throw runtime_error("time_put_byname"
|
||||
__throw_runtime_error("time_put_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
__time_put::__time_put(const string& nm)
|
||||
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__loc_ == 0)
|
||||
throw runtime_error("time_put_byname"
|
||||
__throw_runtime_error("time_put_byname"
|
||||
" failed to construct for " + nm);
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
__time_put::~__time_put()
|
||||
@@ -5792,11 +5774,10 @@ moneypunct_byname<char, false>::init(const char* nm)
|
||||
{
|
||||
typedef moneypunct<char, false> base;
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("moneypunct_byname"
|
||||
__throw_runtime_error("moneypunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->mon_decimal_point)
|
||||
__decimal_point_ = *lc->mon_decimal_point;
|
||||
@@ -5836,11 +5817,10 @@ moneypunct_byname<char, true>::init(const char* nm)
|
||||
{
|
||||
typedef moneypunct<char, true> base;
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("moneypunct_byname"
|
||||
__throw_runtime_error("moneypunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->mon_decimal_point)
|
||||
__decimal_point_ = *lc->mon_decimal_point;
|
||||
@@ -5897,11 +5877,9 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
|
||||
{
|
||||
typedef moneypunct<wchar_t, false> base;
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("moneypunct_byname"
|
||||
__throw_runtime_error("moneypunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->mon_decimal_point)
|
||||
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
|
||||
@@ -5964,11 +5942,10 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
|
||||
{
|
||||
typedef moneypunct<wchar_t, true> base;
|
||||
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (loc == nullptr)
|
||||
throw runtime_error("moneypunct_byname"
|
||||
__throw_runtime_error("moneypunct_byname"
|
||||
" failed to construct for " + string(nm));
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
lconv* lc = __libcpp_localeconv_l(loc.get());
|
||||
if (*lc->mon_decimal_point)
|
||||
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
|
||||
@@ -6050,6 +6027,7 @@ void __throw_runtime_error(const char* msg)
|
||||
throw runtime_error(msg);
|
||||
#else
|
||||
(void)msg;
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -241,6 +241,8 @@ __throw_bad_alloc()
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw bad_alloc();
|
||||
#else
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ void throw_helper( const string& msg )
|
||||
throw T( msg );
|
||||
#else
|
||||
fprintf(stderr, "%s\n", msg.c_str());
|
||||
abort();
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -258,6 +258,7 @@ __throw_system_error(int ev, const char* what_arg)
|
||||
#else
|
||||
(void)ev;
|
||||
(void)what_arg;
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,9 @@ thread::join()
|
||||
if (ec == 0)
|
||||
__t_ = 0;
|
||||
}
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
if (ec)
|
||||
throw system_error(error_code(ec, system_category()), "thread::join failed");
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
__throw_system_error(ec, "thread::join failed");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -69,10 +68,9 @@ thread::detach()
|
||||
if (ec == 0)
|
||||
__t_ = 0;
|
||||
}
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
|
||||
if (ec)
|
||||
throw system_error(error_code(ec, system_category()), "thread::detach failed");
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
__throw_system_error(ec, "thread::detach failed");
|
||||
}
|
||||
|
||||
unsigned
|
||||
|
||||
@@ -54,12 +54,16 @@ std::bad_typeid::what() const _NOEXCEPT
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw std::bad_typeid();
|
||||
#else
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
void __cxxabiv1::__cxa_bad_cast()
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
throw std::bad_cast();
|
||||
#else
|
||||
_VSTD::abort();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user