Index: include/__functional_03 =================================================================== --- include/__functional_03 +++ include/__functional_03 @@ -679,10 +679,8 @@ _Rp function<_Rp()>::operator()() const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_function_call()); return (*__f_)(); } @@ -955,10 +953,8 @@ _Rp function<_Rp(_A0)>::operator()(_A0 __a0) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_function_call()); return (*__f_)(__a0); } @@ -1231,10 +1227,8 @@ _Rp function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_function_call()); return (*__f_)(__a0, __a1); } @@ -1507,10 +1501,8 @@ _Rp function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_function_call()); return (*__f_)(__a0, __a1, __a2); } Index: include/__locale =================================================================== --- include/__locale +++ include/__locale @@ -165,10 +165,8 @@ locale locale::combine(const locale& __other) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!_VSTD::has_facet<_Facet>(__other)) - throw runtime_error("locale::combine: locale missing facet"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("locale::combine: locale missing facet")); return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other))); } Index: include/array =================================================================== --- include/array +++ include/array @@ -108,9 +108,6 @@ #include #include #include -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -209,11 +206,7 @@ array<_Tp, _Size>::at(size_type __n) { if (__n >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("array::at"); -#else - assert(!"array::at out_of_range"); -#endif + __libcpp_throw(out_of_range("array::at out of range")); return __elems_[__n]; } @@ -223,11 +216,7 @@ array<_Tp, _Size>::at(size_type __n) const { if (__n >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("array::at"); -#else - assert(!"array::at out_of_range"); -#endif + __libcpp_throw(out_of_range("array::at out of range")); return __elems_[__n]; } Index: include/bitset =================================================================== --- include/bitset +++ include/bitset @@ -125,9 +125,6 @@ #include #include #include <__functional_base> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include -#endif #include <__undef_min_max> @@ -326,11 +323,7 @@ const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); if (__i != __e) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw overflow_error("bitset to_ulong overflow error"); -#else - assert(!"bitset to_ulong overflow error"); -#endif + __libcpp_throw(overflow_error("bitset to_ulong overflow error")); return __first_[0]; } @@ -349,11 +342,7 @@ const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); if (__i != __e) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw overflow_error("bitset to_ullong overflow error"); -#else - assert(!"bitset to_ullong overflow error"); -#endif + __libcpp_throw(overflow_error("bitset to_ullong overflow error")); return to_ullong(true_type()); } @@ -763,11 +752,7 @@ size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); for (size_t __i = 0; __i < __rlen; ++__i) if (__str[__i] != __zero && __str[__i] != __one) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw invalid_argument("bitset string ctor has invalid argument"); -#else - assert(!"bitset string ctor has invalid argument"); -#endif + __libcpp_throw(invalid_argument("bitset string ctor has invalid argument")); size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) @@ -789,19 +774,11 @@ _CharT __zero, _CharT __one) { if (__pos > __str.size()) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset string pos out of range"); -#else - assert(!"bitset string pos out of range"); -#endif + __libcpp_throw(out_of_range("bitset string pos out of range")); size_t __rlen = _VSTD::min(__n, __str.size() - __pos); for (size_t __i = __pos; __i < __pos + __rlen; ++__i) if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw invalid_argument("bitset string ctor has invalid argument"); -#else - assert(!"bitset string ctor has invalid argument"); -#endif + __libcpp_throw(invalid_argument("bitset string ctor has invalid argument")); size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) @@ -876,11 +853,7 @@ bitset<_Size>::set(size_t __pos, bool __val) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset set argument out of range"); -#else - assert(!"bitset set argument out of range"); -#endif + __libcpp_throw(out_of_range("bitset set argument out of range")); (*this)[__pos] = __val; return *this; } @@ -899,11 +872,7 @@ bitset<_Size>::reset(size_t __pos) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset reset argument out of range"); -#else - assert(!"bitset reset argument out of range"); -#endif + __libcpp_throw(out_of_range("bitset reset argument out of range")); (*this)[__pos] = false; return *this; } @@ -932,11 +901,7 @@ bitset<_Size>::flip(size_t __pos) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset flip argument out of range"); -#else - assert(!"bitset flip argument out of range"); -#endif + __libcpp_throw(out_of_range("bitset flip argument out of range")); reference r = base::__make_ref(__pos); r = ~r; return *this; @@ -1027,11 +992,7 @@ bitset<_Size>::test(size_t __pos) const { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset test argument out of range"); -#else - assert(!"bitset test argument out of range"); -#endif + __libcpp_throw(out_of_range("bitset test argument out of range")); return (*this)[__pos]; } Index: include/complex =================================================================== --- include/complex +++ include/complex @@ -245,9 +245,6 @@ #include #include #include -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header Index: include/deque =================================================================== --- include/deque +++ include/deque @@ -903,18 +903,14 @@ void __deque_base_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("deque"); -#endif + __libcpp_throw(length_error("deque")); } template void __deque_base_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("deque"); -#endif + __libcpp_throw(out_of_range("deque")); } template Index: include/exception =================================================================== --- include/exception +++ include/exception @@ -259,7 +259,7 @@ template _LIBCPP_INLINE_VISIBILITY -inline void __libcpp_throw(_Exception const& __e) { +inline __attribute__((noreturn)) void __libcpp_throw(_Exception const& __e) { #ifndef _LIBCPP_NO_EXCEPTIONS throw __e; #else Index: include/experimental/dynarray =================================================================== --- include/experimental/dynarray +++ include/experimental/dynarray @@ -106,10 +106,6 @@ #include <__undef___deallocate> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -143,11 +139,7 @@ { if ( numeric_limits::max() / sizeof (value_type) <= count ) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_array_length(); -#else - assert(!"dynarray::allocation"); -#endif + __libcpp_throw(bad_array_length()); } return static_cast (_VSTD::__allocate (sizeof(value_type) * count)); } @@ -284,11 +276,7 @@ { if (__n >= __size_) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("dynarray::at"); -#else - assert(!"dynarray::at out_of_range"); -#endif + __libcpp_throw(out_of_range("dynarray::at out of range")); } return data()[__n]; } @@ -300,11 +288,7 @@ { if (__n >= __size_) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("dynarray::at"); -#else - assert(!"dynarray::at out_of_range"); -#endif + __libcpp_throw(out_of_range("dynarray::at out of range")); } return data()[__n]; } Index: include/experimental/optional =================================================================== --- include/experimental/optional +++ include/experimental/optional @@ -517,11 +517,7 @@ constexpr value_type const& value() const { if (!this->__engaged_) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_optional_access(); -#else - assert(!"bad optional access"); -#endif + __libcpp_throw(bad_optional_access()); return this->__val_; } @@ -529,11 +525,7 @@ value_type& value() { if (!this->__engaged_) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_optional_access(); -#else - assert(!"bad optional access"); -#endif + __libcpp_throw(bad_optional_access()); return this->__val_; } Index: include/fstream =================================================================== --- include/fstream +++ include/fstream @@ -618,10 +618,8 @@ size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_); if (__nr != 0) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __libcpp_throw(bad_cast()); __extbufend_ = __extbufnext_ + __nr; char_type* __inext; __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, @@ -700,10 +698,8 @@ codecvt_base::result __r; do { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __libcpp_throw(bad_cast()); const char_type* __e; __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); @@ -793,10 +789,8 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __libcpp_throw(bad_cast()); int __width = __cv_->encoding(); if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) return pos_type(off_type(-1)); @@ -852,10 +846,8 @@ { if (__file_ == 0) return 0; -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __libcpp_throw(bad_cast()); if (__cm_ & ios_base::out) { if (this->pptr() != this->pbase()) Index: include/functional =================================================================== --- include/functional +++ include/functional @@ -1891,10 +1891,8 @@ _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_function_call()); return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); } Index: include/future =================================================================== --- include/future +++ include/future @@ -515,11 +515,7 @@ inline _LIBCPP_ALWAYS_INLINE void __throw_future_error(future_errc _Ev) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw future_error(make_error_code(_Ev)); -#else - assert(!"future_error"); -#endif + __libcpp_throw(future_error(make_error_code(_Ev))); } class _LIBCPP_TYPE_VIS __assoc_sub_state Index: include/locale =================================================================== --- include/locale +++ include/locale @@ -3701,10 +3701,8 @@ if (__r == codecvt_base::ok) return __ws; } -#ifndef _LIBCPP_NO_EXCEPTIONS if (__wide_err_string_.empty()) - throw range_error("wstring_convert: from_bytes error"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(range_error("wstring_convert: from_bytes error")); return __wide_err_string_; } @@ -3790,10 +3788,8 @@ return __bs; } } -#ifndef _LIBCPP_NO_EXCEPTIONS if (__byte_err_string_.empty()) - throw range_error("wstring_convert: to_bytes error"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(range_error("wstring_convert: to_bytes error")); return __byte_err_string_; } Index: include/map =================================================================== --- include/map +++ include/map @@ -1442,10 +1442,8 @@ { __node_base_pointer __parent; __node_base_pointer& __child = __find_equal_key(__parent, __k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) - throw out_of_range("map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(out_of_range("map::at: key not found")); return static_cast<__node_pointer>(__child)->__value_.__cc.second; } @@ -1455,10 +1453,8 @@ { __node_base_pointer __parent; __node_base_pointer __child = __find_equal_key(__parent, __k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) - throw out_of_range("map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(out_of_range("map::at: key not found")); return static_cast<__node_pointer>(__child)->__value_.__cc.second; } Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -610,9 +610,6 @@ #include #include #include -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include -#endif #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) # include @@ -5335,11 +5332,7 @@ __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) { if (__cntrl_ == 0) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_weak_ptr(); -#else - assert(!"bad_weak_ptr"); -#endif + __libcpp_throw(bad_weak_ptr()); } template Index: include/regex =================================================================== --- include/regex +++ include/regex @@ -960,11 +960,7 @@ _LIBCPP_ALWAYS_INLINE void __throw_regex_error() { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw regex_error(_Ev); -#else - assert(!"regex_error"); -#endif + __libcpp_throw(regex_error(_Ev)); } template Index: include/string =================================================================== --- include/string +++ include/string @@ -1177,22 +1177,14 @@ void __basic_string_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("basic_string"); -#else - assert(!"basic_string length_error"); -#endif + __libcpp_throw(length_error("basic_string")); } template void __basic_string_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("basic_string"); -#else - assert(!"basic_string out_of_range"); -#endif + __libcpp_throw(out_of_range("basic_string")); } #ifdef _LIBCPP_MSVC Index: include/unordered_map =================================================================== --- include/unordered_map +++ include/unordered_map @@ -1440,10 +1440,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) { iterator __i = find(__k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__i == end()) - throw out_of_range("unordered_map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(out_of_range("unordered_map::at: key not found")); return __i->second; } @@ -1452,10 +1450,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const { const_iterator __i = find(__k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__i == end()) - throw out_of_range("unordered_map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(out_of_range("unordered_map::at: key not found"))); return __i->second; } Index: include/vector =================================================================== --- include/vector +++ include/vector @@ -298,22 +298,14 @@ void __vector_base_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("vector"); -#else - assert(!"vector length_error"); -#endif + __libcpp_throw(length_error("vector")); } template void __vector_base_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("vector"); -#else - assert(!"vector out_of_range"); -#endif + __libcpp_throw(out_of_range("vector")); } #ifdef _LIBCPP_MSVC Index: src/debug.cpp =================================================================== --- src/debug.cpp +++ src/debug.cpp @@ -152,11 +152,7 @@ size_t nc = __next_prime(2*static_cast(__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 + __libcpp_throw(bad_alloc()); for (__c_node** p = __cbeg_; p != __cend_; ++p) { __c_node* q = *p; @@ -178,11 +174,7 @@ __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 + __libcpp_throw(bad_alloc()); r->__c_ = __c; r->__next_ = p; ++__csz_; @@ -475,11 +467,7 @@ __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 + __libcpp_throw(bad_alloc()); if (nc > 1) memcpy(beg, beg_, nc/2*sizeof(__i_node*)); free(beg_); @@ -501,11 +489,7 @@ size_t nc = __next_prime(2*static_cast(__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 + __libcpp_throw(bad_alloc()); for (__i_node** p = __ibeg_; p != __iend_; ++p) { __i_node* q = *p; @@ -527,11 +511,7 @@ __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 + __libcpp_throw(bad_alloc()); ::new(r) __i_node(__i, p, nullptr); ++__isz_; return r; Index: src/experimental/memory_resource.cpp =================================================================== --- src/experimental/memory_resource.cpp +++ src/experimental/memory_resource.cpp @@ -50,11 +50,7 @@ protected: virtual void* do_allocate(size_t, size_t) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_alloc(); -#else - abort(); -#endif + __libcpp_throw(std::bad_alloc()); } virtual void do_deallocate(void *, size_t, size_t) {} virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT @@ -136,4 +132,4 @@ return __default_memory_resource(true, __new_res); } -_LIBCPP_END_NAMESPACE_LFTS_PMR \ No newline at end of file +_LIBCPP_END_NAMESPACE_LFTS_PMR Index: src/future.cpp =================================================================== --- src/future.cpp +++ src/future.cpp @@ -92,10 +92,8 @@ __assoc_sub_state::set_value() { unique_lock __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::promise_already_satisfied))); __state_ |= __constructed | ready; __cv_.notify_all(); } @@ -104,10 +102,8 @@ __assoc_sub_state::set_value_at_thread_exit() { unique_lock __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::promise_already_satisfied))); __state_ |= __constructed; __thread_local_data()->__make_ready_at_thread_exit(this); } @@ -116,10 +112,8 @@ __assoc_sub_state::set_exception(exception_ptr __p) { unique_lock __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::promise_already_satisfied))); __exception_ = __p; __state_ |= ready; __cv_.notify_all(); @@ -129,10 +123,8 @@ __assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p) { unique_lock __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __libcxx_throw(future_error(make_error_code(future_errc::promise_already_satisfied))); __exception_ = __p; __thread_local_data()->__make_ready_at_thread_exit(this); } @@ -181,18 +173,14 @@ void __assoc_sub_state::__execute() { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); } future::future(__assoc_sub_state* __state) : __state_(__state) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_->__has_future_attached()) - throw future_error(make_error_code(future_errc::future_already_retrieved)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::future_already_retrieved))); __state_->__add_shared(); __state_->__set_future_attached(); } @@ -234,50 +222,40 @@ future promise::get_future() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); return future(__state_); } void promise::set_value() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); __state_->set_value(); } void promise::set_exception(exception_ptr __p) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); __state_->set_exception(__p); } void promise::set_value_at_thread_exit() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); __state_->set_value_at_thread_exit(); } void promise::set_exception_at_thread_exit(exception_ptr __p) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __libcpp_throw(future_error(make_error_code(future_errc::no_state))); __state_->set_exception_at_thread_exit(__p); } Index: src/hash.cpp =================================================================== --- src/hash.cpp +++ src/hash.cpp @@ -154,12 +154,8 @@ typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFB) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __libcpp_throw(overflow_error("__next_prime overflow")); } template @@ -167,12 +163,8 @@ typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFFFFFFFFC5ull) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __libcpp_throw(overflow_error("__next_prime overflow")); } size_t Index: src/ios.cpp =================================================================== --- src/ios.cpp +++ src/ios.cpp @@ -266,10 +266,8 @@ __rdstate_ = state; else __rdstate_ = state | badbit; -#ifndef _LIBCPP_NO_EXCEPTIONS if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0) - throw failure("ios_base::clear"); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(failure("ios_base::clear")); } // init @@ -309,35 +307,27 @@ { size_t newesize = sizeof(event_callback) * rhs.__event_size_; new_callbacks.reset(static_cast(malloc(newesize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_callbacks) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_alloc()); size_t newisize = sizeof(int) * rhs.__event_size_; new_ints.reset(static_cast(malloc(newisize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_ints) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_alloc()); } if (__iarray_cap_ < rhs.__iarray_size_) { size_t newsize = sizeof(long) * rhs.__iarray_size_; new_longs.reset(static_cast(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_longs) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_alloc()); } if (__parray_cap_ < rhs.__parray_size_) { size_t newsize = sizeof(void*) * rhs.__parray_size_; new_pointers.reset(static_cast(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_pointers) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_alloc()); } // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_ __fmtflags_ = rhs.__fmtflags_; Index: src/locale.cpp =================================================================== --- src/locale.cpp +++ src/locale.cpp @@ -436,10 +436,8 @@ const locale::facet* locale::__imp::use_facet(long id) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!has_facet(id)) - throw bad_cast(); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(bad_cast()); return facets_[static_cast(id)]; } @@ -528,6 +526,7 @@ #else // _LIBCPP_NO_EXCEPTIONS : __locale_(new __imp(*other.__locale_, name, c)) #endif + { __locale_->__add_shared(); } @@ -646,22 +645,18 @@ : collate(refs), __l(newlocale(LC_ALL_MASK, n, 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("collate_byname::collate_byname" - " failed to construct for " + string(n)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("collate_byname::collate_byname" + " failed to construct for " + string(n))); } collate_byname::collate_byname(const string& name, size_t refs) : collate(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("collate_byname::collate_byname" - " failed to construct for " + name); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("collate_byname::collate_byname" + " failed to construct for " + name)); } collate_byname::~collate_byname() @@ -698,22 +693,18 @@ : collate(refs), __l(newlocale(LC_ALL_MASK, n, 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("collate_byname::collate_byname(size_t refs)" - " failed to construct for " + string(n)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("collate_byname::collate_byname(" + "size_t refs) failed to construct for " + string(n))); } collate_byname::collate_byname(const string& name, size_t refs) : collate(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("collate_byname::collate_byname(size_t refs)" - " failed to construct for " + name); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("collate_byname::collate_byname" + "(size_t refs) failed to construct for " + name)); } collate_byname::~collate_byname() @@ -1172,22 +1163,18 @@ : ctype(0, false, refs), __l(newlocale(LC_ALL_MASK, name, 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("ctype_byname::ctype_byname" - " failed to construct for " + string(name)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("ctype_byname::ctype_byname" + " failed to construct for " + string(name))); } ctype_byname::ctype_byname(const string& name, size_t refs) : ctype(0, false, refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("ctype_byname::ctype_byname" - " failed to construct for " + name); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("ctype_byname::ctype_byname" + " failed to construct for " + name)); } ctype_byname::~ctype_byname() @@ -1229,22 +1216,18 @@ : ctype(refs), __l(newlocale(LC_ALL_MASK, name, 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("ctype_byname::ctype_byname" - " failed to construct for " + string(name)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("ctype_byname::ctype_byname" + " failed to construct for " + string(name))); } ctype_byname::ctype_byname(const string& name, size_t refs) : ctype(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("ctype_byname::ctype_byname" - " failed to construct for " + name); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("ctype_byname::ctype_byname" + " failed to construct for " + name)); } ctype_byname::~ctype_byname() @@ -1504,11 +1487,10 @@ : locale::facet(refs), __l(newlocale(LC_ALL_MASK, nm, 0)) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) - throw runtime_error("codecvt_byname::codecvt_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("codecvt_byname" + "::codecvt_byname failed to construct " + "for " + string(nm))); } codecvt::~codecvt() @@ -4257,11 +4239,10 @@ 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::numpunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("numpunct_byname::" + "numpunct_byname failed to construct " + "for " + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; @@ -4296,11 +4277,10 @@ 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::numpunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("numpunct_byname::numpunct_" + "byname failed to construct for " + + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; @@ -4703,21 +4683,17 @@ __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" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("time_get_byname" + " failed to construct for " + string(nm))); } __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" - " failed to construct for " + nm); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("time_get_byname" + " failed to construct for " + nm)); } __time_get::~__time_get() @@ -5363,21 +5339,17 @@ __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" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("time_put_byname" + " failed to construct for " + string(nm))); } __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" - " failed to construct for " + nm); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("time_put_byname" + " failed to construct for " + nm)); } __time_put::~__time_put() @@ -5792,11 +5764,9 @@ { typedef moneypunct base; __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); -#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == nullptr) - throw runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("moneypunct_byname" + " failed to construct for " + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; @@ -5836,11 +5806,9 @@ { typedef moneypunct base; __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); -#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == nullptr) - throw runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("moneypunct_byname" + " failed to construct for " + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; @@ -5897,11 +5865,9 @@ { typedef moneypunct base; __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); -#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == nullptr) - throw runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("moneypunct_byname" + " failed to construct for " + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast(*lc->mon_decimal_point); @@ -5964,11 +5930,9 @@ { typedef moneypunct base; __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); -#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == nullptr) - throw runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); -#endif // _LIBCPP_NO_EXCEPTIONS + __libcpp_throw(runtime_error("moneypunct_byname" + " failed to construct for " + string(nm))); lconv* lc = __libcpp_localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast(*lc->mon_decimal_point); @@ -6046,11 +6010,8 @@ void __throw_runtime_error(const char* msg) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw runtime_error(msg); -#else + __libcpp_throw(runtime_error(msg)); (void)msg; -#endif } template class collate; Index: src/new.cpp =================================================================== --- src/new.cpp +++ src/new.cpp @@ -56,7 +56,7 @@ nh(); else #ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_alloc(); + __libcpp_throw(std::bad_alloc()); #else break; #endif Index: src/string.cpp =================================================================== --- src/string.cpp +++ src/string.cpp @@ -32,28 +32,16 @@ namespace { -template -inline -void throw_helper( const string& msg ) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - throw T( msg ); -#else - fprintf(stderr, "%s\n", msg.c_str()); - abort(); -#endif -} - inline void throw_from_string_out_of_range( const string& func ) { - throw_helper(func + ": out of range"); + __libcpp_throw(out_of_range(func + ": out of range")); } inline void throw_from_string_invalid_arg( const string& func ) { - throw_helper(func + ": no conversion"); + __libcpp_throw(invalid_argument(func + ": no conversion")); } // as_integer Index: src/system_error.cpp =================================================================== --- src/system_error.cpp +++ src/system_error.cpp @@ -253,12 +253,7 @@ void __throw_system_error(int ev, const char* what_arg) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw system_error(error_code(ev, system_category()), what_arg); -#else - (void)ev; - (void)what_arg; -#endif + __libcpp_throw(system_error(error_code(ev, system_category()), what_arg)); } _LIBCPP_END_NAMESPACE_STD Index: src/thread.cpp =================================================================== --- src/thread.cpp +++ src/thread.cpp @@ -53,10 +53,9 @@ 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 + __libcpp_throw(system_error(error_code(ec, system_category()), + "thread::join failed")); } void @@ -69,10 +68,9 @@ 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 + __libcpp_throw(system_error(error_code(ec, system_category()), + "thread::detach failed")); } unsigned Index: src/typeinfo.cpp =================================================================== --- src/typeinfo.cpp +++ src/typeinfo.cpp @@ -52,15 +52,11 @@ // because bad_cast and bad_typeid are defined in his higher level library void __cxxabiv1::__cxa_bad_typeid() { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_typeid(); -#endif + __libcpp_throw(std::bad_typeid()); } void __cxxabiv1::__cxa_bad_cast() { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_cast(); -#endif + __libcpp_throw(std::bad_cast()); } #endif