From d05f74f16e130e97210ad2eaad12915192ea8c9e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 7 May 2007 17:27:54 -0400 Subject: re PR other/28145 (C++ (throw() and catch(...) {/* fall through */ } ) and pthread cancellation are incompatible (at least with NPTL)) PR c++/28145 * libsupc++/cxxabi.h (__forced_unwind, __foreign_exception): New classes. * libsupc++/eh_exception.cc: Define their destructors. * config/abi/pre/gnu.ver: Export their type_infos. * config/abi/pre/gnu-versioned-namespace.ver: Likewise. * libsupc++/eh_personality.cc: A handler for abi::__forced_unwind matches a forced unwind, and a handler for abi::__foreign_exception matches a foreign exception. * include/bits/istream.tcc: Rethrow forced unwind. * include/bits/ostream.tcc: Likewise. * include/bits/ostream_insert.h: Likewise. * include/bits/basic_string.tcc (operator>>, getline): Likewise. * include/bits/fstream.tcc (basic_filebuf::close): Likewise. * include/ext/vstring.cc (operator>>, getline): Likewise. * src/istream.cc: Likewise. * src/compatibility.cc (basic_istream::ignore): Likewise. * include/std/bitset (operator>>): Likewise. * include/std/fstream (basic_filebuf::close): Remove throw() spec. * libsupc++/cxxabi-internal.h: Split out from... * libsupc++/cxxabi.h: ...here. From-SVN: r124517 --- libstdc++-v3/include/bits/basic_string.tcc | 12 +++ libstdc++-v3/include/bits/fstream.tcc | 73 ++++++++------ libstdc++-v3/include/bits/istream.tcc | 107 +++++++++++++++++++++ libstdc++-v3/include/bits/locale_classes.h | 2 +- libstdc++-v3/include/bits/ostream.tcc | 78 +++++++++++---- libstdc++-v3/include/bits/ostream_insert.h | 6 ++ libstdc++-v3/include/debug/deque | 2 +- .../hash_load_check_resize_trigger_imp.hpp | 2 +- libstdc++-v3/include/ext/vstring.tcc | 12 +++ libstdc++-v3/include/std/bitset | 6 ++ libstdc++-v3/include/std/fstream | 2 +- libstdc++-v3/include/tr1/hypergeometric.tcc | 4 +- 12 files changed, 253 insertions(+), 53 deletions(-) (limited to 'libstdc++-v3/include') diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 7483371..4c68293 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -46,6 +46,8 @@ #pragma GCC system_header +#include + _GLIBCXX_BEGIN_NAMESPACE(std) template @@ -1015,6 +1017,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= __ios_base::eofbit; __in.width(0); } + catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(__ios_base::badbit); + __throw_exception_again; + } catch(...) { // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -1074,6 +1081,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else __err |= __ios_base::failbit; } + catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(__ios_base::badbit); + __throw_exception_again; + } catch(...) { // _GLIBCXX_RESOLVE_LIB_DEFECTS diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 54e75db..f9b84bf 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -42,6 +42,8 @@ #pragma GCC system_header +#include + _GLIBCXX_BEGIN_NAMESPACE(std) template @@ -127,36 +129,51 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template typename basic_filebuf<_CharT, _Traits>::__filebuf_type* basic_filebuf<_CharT, _Traits>:: - close() throw() + close() { - __filebuf_type* __ret = NULL; - if (this->is_open()) + if (!this->is_open()) + return NULL; + + bool __testfail = false; + { + // NB: Do this here so that re-opened filebufs will be cool... + struct __close_sentry { - bool __testfail = false; - try - { - if (!_M_terminate_output()) - __testfail = true; - } - catch(...) - { __testfail = true; } - - // NB: Do this here so that re-opened filebufs will be cool... - _M_mode = ios_base::openmode(0); - _M_pback_init = false; - _M_destroy_internal_buffer(); - _M_reading = false; - _M_writing = false; - _M_set_buffer(-1); - _M_state_last = _M_state_cur = _M_state_beg; - - if (!_M_file.close()) - __testfail = true; - - if (!__testfail) - __ret = this; - } - return __ret; + basic_filebuf *__fb; + __close_sentry (basic_filebuf *__fbi): __fb(__fbi) { } + ~__close_sentry () + { + __fb->_M_mode = ios_base::openmode(0); + __fb->_M_pback_init = false; + __fb->_M_destroy_internal_buffer(); + __fb->_M_reading = false; + __fb->_M_writing = false; + __fb->_M_set_buffer(-1); + __fb->_M_state_last = __fb->_M_state_cur = __fb->_M_state_beg; + } + } __cs (this); + + try + { + if (!_M_terminate_output()) + __testfail = true; + } + catch(__cxxabiv1::__forced_unwind&) + { + _M_file.close(); + __throw_exception_again; + } + catch(...) + { __testfail = true; } + } + + if (!_M_file.close()) + __testfail = true; + + if (__testfail) + return NULL; + else + return this; } template diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 4588b9c..e6b18cd 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -43,6 +43,8 @@ #pragma GCC system_header +#include + _GLIBCXX_BEGIN_NAMESPACE(std) template @@ -98,6 +100,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const __num_get_type& __ng = __check_facet(this->_M_num_get); __ng.get(*this, 0, *this, __err, __v); } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -163,6 +170,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (__ineof) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::failbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::failbit); } } @@ -194,6 +206,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } } @@ -226,6 +243,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } } @@ -264,6 +286,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (traits_type::eq_int_type(__c, __eof)) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } } @@ -307,6 +334,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (traits_type::eq_int_type(__c, __eof)) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } } @@ -355,6 +387,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= ios_base::failbit; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } } @@ -392,6 +429,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else _M_gcount = 1; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -449,6 +491,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (traits_type::eq_int_type(__c, __eof)) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -509,6 +556,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __sb->sbumpc(); } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -534,6 +586,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (traits_type::eq_int_type(__c, traits_type::eof())) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -558,6 +615,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (_M_gcount != __n) __err |= (ios_base::eofbit | ios_base::failbit); } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -585,6 +647,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else if (__num == -1) __err |= ios_base::eofbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -613,6 +680,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) || traits_type::eq_int_type(__sb->sputbackc(__c), __eof)) __err |= ios_base::badbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -641,6 +713,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) || traits_type::eq_int_type(__sb->sungetc(), __eof)) __err |= ios_base::badbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -672,6 +749,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __ret = 0; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -694,6 +776,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } return __ret; @@ -720,6 +807,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= ios_base::failbit; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -748,6 +840,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= ios_base::failbit; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -775,6 +872,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) else __err |= (ios_base::eofbit | ios_base::failbit); } + catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { __in._M_setstate(ios_base::badbit); } if (__err) @@ -828,6 +930,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) *__s = char_type(); __in.width(0); } + catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { __in._M_setstate(ios_base::badbit); } } diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index 141f44c..5e6a810 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -409,7 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { try { delete this; } - catch (...) + catch(...) { } } } diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 8ef9d89..4691c64 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -43,6 +43,8 @@ #pragma GCC system_header +#include + _GLIBCXX_BEGIN_NAMESPACE(std) template @@ -76,6 +78,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (__np.put(*this, *this, this->fill(), __v).failed()) __err |= ios_base::badbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -126,6 +133,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (!__copy_streambufs(__sbin, this->rdbuf())) __err |= ios_base::failbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::failbit); } } @@ -157,7 +169,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (traits_type::eq_int_type(__put, traits_type::eof())) __err |= ios_base::badbit; } - catch (...) + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } + catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) this->setstate(__err); @@ -182,7 +199,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { try { _M_write(__s, __n); } - catch (...) + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } + catch(...) { this->_M_setstate(ios_base::badbit); } } return *this; @@ -202,6 +224,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (this->rdbuf() && this->rdbuf()->pubsync() == -1) __err |= ios_base::badbit; } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -220,6 +247,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (!this->fail()) __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } return __ret; @@ -245,6 +277,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= ios_base::failbit; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -272,6 +309,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __err |= ios_base::failbit; } } + catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) @@ -289,31 +331,29 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 167. Improper use of traits_type::length() - const size_t __clen = char_traits::length(__s); - _CharT* __ws = 0; + const size_t __clen = char_traits::length(__s); try - { - __ws = new _CharT[__clen]; - for (size_t __i = 0; __i < __clen; ++__i) - __ws[__i] = __out.widen(__s[__i]); - } - catch(...) { - delete [] __ws; - __out._M_setstate(ios_base::badbit); - return __out; - } + struct __ptr_guard + { + _CharT *p; + __ptr_guard (_CharT *ip): p(ip) { } + ~__ptr_guard() { delete[] p; } + _CharT* __get() { return p; } + } __pg (new _CharT[__clen]); - try - { + _CharT *__ws = __pg.__get(); + for (size_t __i = 0; __i < __clen; ++__i) + __ws[__i] = __out.widen(__s[__i]); __ostream_insert(__out, __ws, __clen); - delete [] __ws; } - catch(...) + catch(__cxxabiv1::__forced_unwind&) { - delete [] __ws; + __out._M_setstate(ios_base::badbit); __throw_exception_again; } + catch(...) + { __out._M_setstate(ios_base::badbit); } } return __out; } diff --git a/libstdc++-v3/include/bits/ostream_insert.h b/libstdc++-v3/include/bits/ostream_insert.h index e9e83fb..5815de9 100644 --- a/libstdc++-v3/include/bits/ostream_insert.h +++ b/libstdc++-v3/include/bits/ostream_insert.h @@ -38,6 +38,7 @@ #pragma GCC system_header #include +#include _GLIBCXX_BEGIN_NAMESPACE(std) @@ -103,6 +104,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __ostream_write(__out, __s, __n); __out.width(0); } + catch(__cxxabiv1::__forced_unwind&) + { + __out._M_setstate(__ios_base::badbit); + __throw_exception_again; + } catch(...) { __out._M_setstate(__ios_base::badbit); } } diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 79142d9..6e523b8 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -313,7 +313,7 @@ namespace __debug return iterator(_Base::erase(__first.base(), __last.base()), this); } - catch (...) + catch(...) { this->_M_revalidate_singular(); __throw_exception_again; diff --git a/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp b/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp index aa29e07..9c67375 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp @@ -265,7 +265,7 @@ set_loads(std::pair load_pair) m_load_max = load_pair.second; do_resize(static_cast(size_base::get_size() / ((m_load_min + m_load_max) / 2))); } - catch (...) + catch(...) { m_load_min = old_load_min; m_load_max = old_load_max; diff --git a/libstdc++-v3/include/ext/vstring.tcc b/libstdc++-v3/include/ext/vstring.tcc index 7d03017..7f3478a 100644 --- a/libstdc++-v3/include/ext/vstring.tcc +++ b/libstdc++-v3/include/ext/vstring.tcc @@ -38,6 +38,8 @@ #pragma GCC system_header +#include + _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) template // For invalid_argument, out_of_range, // overflow_error #include +#include #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * sizeof(unsigned long)) #define _GLIBCXX_BITSET_WORDS(__n) \ @@ -1271,6 +1272,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) } } } + catch(__cxxabiv1::__forced_unwind&) + { + __is._M_setstate(__ios_base::badbit); + __throw_exception_again; + } catch(...) { __is._M_setstate(__ios_base::badbit); } } diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream index cab18c1..18c24be 100644 --- a/libstdc++-v3/include/std/fstream +++ b/libstdc++-v3/include/std/fstream @@ -275,7 +275,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) * If any operations fail, this function also fails. */ __filebuf_type* - close() throw(); + close(); protected: void diff --git a/libstdc++-v3/include/tr1/hypergeometric.tcc b/libstdc++-v3/include/tr1/hypergeometric.tcc index d54e6fe..c0d676f 100644 --- a/libstdc++-v3/include/tr1/hypergeometric.tcc +++ b/libstdc++-v3/include/tr1/hypergeometric.tcc @@ -613,7 +613,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __sgn_g1cb = __log_gamma_sign(__c - __b); __ln_g1cb = __log_gamma(__c - __b); } - catch (...) + catch(...) { __ok1 = false; } @@ -628,7 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __sgn_g2b = __log_gamma_sign(__b); __ln_g2b = __log_gamma(__b); } - catch (...) + catch(...) { __ok2 = false; } -- cgit v1.1