From 8d1b99e26ad5c88a05c7c7ba2fbb05bdc345e9d2 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Mon, 10 Aug 2009 18:24:47 +0000 Subject: [PATCH] future: Fixes for -fno-exceptions. 2009-08-10 Benjamin Kosnik * include/std/future: Fixes for -fno-exceptions. * include/bits/functexcept.h: Same. * libsupc++/exception_ptr.h: Same. * src/pool_allocator.cc: Same. * src/future.cc: Same. * src/functexcept.cc: Same. * config/abi/pre/gnu.ver: New exports. * testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust. * testsuite/30_threads/packaged_task/cons/copy_neg.cc: Same. * testsuite/30_threads/unique_future/cons/assign_neg.cc: Same. * testsuite/30_threads/unique_future/cons/copy_neg.cc: Same. * testsuite/30_threads/shared_future/cons/assign_neg.cc: Same. * testsuite/30_threads/promise/cons/assign_neg.cc: Same. * testsuite/30_threads/promise/cons/copy_neg.cc: Same. * testsuite/23_containers/deque/operators/1.cc: Separate in two... * testsuite/23_containers/deque/operators/2.cc: New. From-SVN: r150633 --- libstdc++-v3/ChangeLog | 20 ++++++++ libstdc++-v3/config/abi/pre/gnu.ver | 12 +++-- libstdc++-v3/include/bits/functexcept.h | 3 ++ libstdc++-v3/include/std/future | 45 +++++++++++------ libstdc++-v3/libsupc++/exception_ptr.h | 4 +- libstdc++-v3/src/functexcept.cc | 15 +++++- libstdc++-v3/src/future.cc | 5 ++ libstdc++-v3/src/pool_allocator.cc | 4 +- .../23_containers/deque/operators/1.cc | 22 -------- .../23_containers/deque/operators/2.cc | 50 +++++++++++++++++++ .../packaged_task/cons/assign_neg.cc | 2 +- .../30_threads/packaged_task/cons/copy_neg.cc | 2 +- .../30_threads/promise/cons/assign_neg.cc | 2 +- .../30_threads/promise/cons/copy_neg.cc | 2 +- .../shared_future/cons/assign_neg.cc | 2 +- .../unique_future/cons/assign_neg.cc | 2 +- .../30_threads/unique_future/cons/copy_neg.cc | 2 +- 17 files changed, 142 insertions(+), 52 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/deque/operators/2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f6d6f507cb77..3b9b506b3756 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2009-08-10 Benjamin Kosnik + + * include/std/future: Fixes for -fno-exceptions. + * include/bits/functexcept.h: Same. + * libsupc++/exception_ptr.h: Same. + * src/pool_allocator.cc: Same. + * src/future.cc: Same. + * src/functexcept.cc: Same. + * config/abi/pre/gnu.ver: New exports. + * testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust. + * testsuite/30_threads/packaged_task/cons/copy_neg.cc: Same. + * testsuite/30_threads/unique_future/cons/assign_neg.cc: Same. + * testsuite/30_threads/unique_future/cons/copy_neg.cc: Same. + * testsuite/30_threads/shared_future/cons/assign_neg.cc: Same. + * testsuite/30_threads/promise/cons/assign_neg.cc: Same. + * testsuite/30_threads/promise/cons/copy_neg.cc: Same. + + * testsuite/23_containers/deque/operators/1.cc: Separate in two... + * testsuite/23_containers/deque/operators/2.cc: New. + 2009-08-07 Paolo Carlini * src/hash.cc (hash::operator()(string), diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 9fcf6ce7a105..c4967db55137 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -517,7 +517,7 @@ GLIBCXX_3.4 { _ZTVSt13bad_exception; _ZTVSt[0-9][0-9]basic*; _ZTVSt[0-9][0-9][c-d]*; - _ZTVSt[0-9][0-9][f-k]*; + _ZTVSt[0-9][0-9][g-k]*; _ZTVSt11logic_error; _ZTVSt12length_error; _ZTVSt[0-9][0-9][m-r]*; @@ -545,7 +545,7 @@ GLIBCXX_3.4 { _ZTISt13bad_exception; _ZTISt[0-9][0-9]basic*; _ZTISt[0-9][0-9][c-d]*; - _ZTISt[0-9][0-9][f-k]*; + _ZTISt[0-9][0-9][g-k]*; _ZTISt11logic_error; _ZTISt12length_error; _ZTISt[0-9][0-9][m-r]*; @@ -577,7 +577,7 @@ GLIBCXX_3.4 { _ZTSSt13bad_exception; _ZTSSt[0-9][0-9]basic*; _ZTSSt[0-9][0-9][c-d]*; - _ZTSSt[0-9][0-9][f-k]*; + _ZTSSt[0-9][0-9][g-k]*; _ZTSSt11logic_error; _ZTSSt12length_error; _ZTSSt[0-9][0-9][m-r]*; @@ -973,6 +973,12 @@ GLIBCXX_3.4.13 { # future _ZSt15future_category; + _ZNSt12future_errorD*; + _ZNKSt12future_error4whatEv; + _ZTSSt12future_error; + _ZTVSt12future_error; + _ZTISt12future_error; + _ZSt20__throw_future_errori; } GLIBCXX_3.4.12; diff --git a/libstdc++-v3/include/bits/functexcept.h b/libstdc++-v3/include/bits/functexcept.h index 9315d3409dca..62174819118b 100644 --- a/libstdc++-v3/include/bits/functexcept.h +++ b/libstdc++-v3/include/bits/functexcept.h @@ -88,6 +88,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void __throw_system_error(int) __attribute__((__noreturn__)); + void + __throw_future_error(int) __attribute__((__noreturn__)); + _GLIBCXX_END_NAMESPACE #endif diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index c5ece9264636..53ad4fee503b 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -76,20 +76,26 @@ namespace std inline error_condition make_error_condition(future_errc __errc) { return error_condition(static_cast(__errc), *future_category); } - /// Exception type thrown by futures. + /** + * @brief Exception type thrown by futures. + * @ingroup exceptions + */ class future_error : public logic_error { + error_code _M_code; + public: explicit future_error(future_errc __ec) : logic_error("std::future_error"), _M_code(make_error_code(__ec)) { } - const error_code& code() const throw() { return _M_code; } + virtual ~future_error() throw(); - const char* what() const throw() { return _M_code.message().c_str(); } + virtual const char* + what() const throw(); - private: - error_code _M_code; + const error_code& + code() const throw() { return _M_code; } }; // Forward declarations. @@ -200,7 +206,7 @@ namespace std { lock_guard __lock(_M_mutex); if (_M_ready()) - throw future_error(future_errc::promise_already_satisfied); + __throw_future_error(int(future_errc::promise_already_satisfied)); _M_result.swap(__res); } _M_cond.notify_all(); @@ -226,7 +232,7 @@ namespace std _M_set_retrieved_flag() { if (_M_retrieved.test_and_set()) - throw future_error(future_errc::future_already_retrieved); + __throw_future_error(int(future_errc::future_already_retrieved)); } private: @@ -366,7 +372,7 @@ namespace std if (static_cast(this->_M_state)) this->_M_state->_M_set_retrieved_flag(); else - throw future_error(future_errc::future_already_retrieved); + __throw_future_error(int(future_errc::future_already_retrieved)); } // copy construction from a shared_future @@ -878,15 +884,17 @@ namespace std unique_future<_Result> get_future() { - try + __try { return _M_promise.get_future(); } - catch (const future_error& __e) + __catch (const future_error& __e) { +#ifdef __EXCEPTIONS if (__e.code() == future_errc::future_already_retrieved) - throw std::bad_function_call(); - throw; + throw std::bad_function_call(); + throw; +#endif } } @@ -895,13 +903,20 @@ namespace std operator()(_ArgTypes... __args) { if (!static_cast(_M_task) || _M_promise._M_satisfied()) - throw std::bad_function_call(); - try + { +#ifdef __EXCEPTIONS + throw std::bad_function_call(); +#else + __builtin_abort(); +#endif + } + + __try { _Run_task<_Result, _ArgTypes...>::_S_run(_M_promise, _M_task, std::forward<_ArgTypes>(__args)...); } - catch (...) + __catch (...) { _M_promise.set_exception(current_exception()); } diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h index 23477c9c3a63..9192a2244e74 100644 --- a/libstdc++-v3/libsupc++/exception_ptr.h +++ b/libstdc++-v3/libsupc++/exception_ptr.h @@ -156,11 +156,13 @@ namespace std { __try { +#ifdef __EXCEPTIONS throw __ex; +#endif } __catch(...) { - return current_exception (); + return current_exception(); } } diff --git a/libstdc++-v3/src/functexcept.cc b/libstdc++-v3/src/functexcept.cc index 057c037e953b..352a6b70aef2 100644 --- a/libstdc++-v3/src/functexcept.cc +++ b/libstdc++-v3/src/functexcept.cc @@ -24,10 +24,11 @@ #include #include #include -#include #include #include #include +#include +#include #ifdef _GLIBCXX_USE_NLS # include @@ -98,6 +99,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void __throw_system_error(int __i) { throw system_error(error_code(__i, generic_category())); } + + void + __throw_future_error(int __i) + { throw future_error(future_errc(__i)); } + #else void __throw_bad_exception(void) @@ -156,8 +162,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { std::abort(); } void - __throw_system_error(int __i) + __throw_system_error(int) { std::abort(); } + + void + __throw_future_error(int) + { std::abort(); } + #endif //__EXCEPTIONS _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/src/future.cc b/libstdc++-v3/src/future.cc index ab9d5dbcc694..f4ef7856a184 100644 --- a/libstdc++-v3/src/future.cc +++ b/libstdc++-v3/src/future.cc @@ -67,6 +67,11 @@ namespace namespace std { const error_category* const future_category = &__future_category_instance(); + + future_error::~future_error() throw() { } + + const char* + future_error::what() const throw() { return _M_code.message().c_str(); } } #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/src/pool_allocator.cc b/libstdc++-v3/src/pool_allocator.cc index e0da5e738842..ebaa394900ba 100644 --- a/libstdc++-v3/src/pool_allocator.cc +++ b/libstdc++-v3/src/pool_allocator.cc @@ -90,11 +90,11 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) size_t __bytes_to_get = (2 * __total_bytes + _M_round_up(_S_heap_size >> 4)); - try + __try { _S_start_free = static_cast(::operator new(__bytes_to_get)); } - catch (...) + __catch (...) { // Try to make do with what we have. That can't hurt. We // do not try smaller requests, since that tends to result diff --git a/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc b/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc index ccc95f3c7666..5db862186cef 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc @@ -55,30 +55,8 @@ void test01() VERIFY( constend <= end ); } -// libstdc++/7186 -void test02() -{ - bool test __attribute__((unused)) = true; - - std::deque d(2); - typedef std::deque::iterator iter; - typedef std::deque::const_iterator constiter; - - iter beg = d.begin(); - iter end = d.end(); - constiter constbeg = d.begin(); - constiter constend = d.end(); - - VERIFY( beg - constbeg == 0 ); - VERIFY( constend - end == 0 ); - - VERIFY( end - constbeg > 0 ); - VERIFY( constend - beg > 0 ); -} - int main() { test01(); - test02(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc b/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc new file mode 100644 index 000000000000..4db5e0ee209f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc @@ -0,0 +1,50 @@ +// 2002-05-18 Paolo Carlini + +// Copyright (C) 2002, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.2.1 deque operators + +#include +#include + +// libstdc++/7186 +void test02() +{ + bool test __attribute__((unused)) = true; + + std::deque d(2); + typedef std::deque::iterator iter; + typedef std::deque::const_iterator constiter; + + iter beg = d.begin(); + iter end = d.end(); + constiter constbeg = d.begin(); + constiter constend = d.end(); + + VERIFY( beg - constbeg == 0 ); + VERIFY( constend - end == 0 ); + + VERIFY( end - constbeg > 0 ); + VERIFY( constend - beg > 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc index 5f02dea01563..0bad6ba2f327 100644 --- a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc @@ -33,4 +33,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 32 } -// { dg-error "deleted function" "" { target *-*-* } 856 } +// { dg-error "deleted function" "" { target *-*-* } 862 } diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc index 6a50d7802aa0..655ca8c2f95a 100644 --- a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 855 } +// { dg-error "deleted function" "" { target *-*-* } 861 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc index cebe5f981d8f..f2fbf178c363 100644 --- a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc @@ -33,4 +33,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 32 } -// { dg-error "deleted function" "" { target *-*-* } 582 } +// { dg-error "deleted function" "" { target *-*-* } 588 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc index cbcdcfb6d250..17757aed0ad6 100644 --- a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 566 } +// { dg-error "deleted function" "" { target *-*-* } 572 } diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc index 3b446d06de5a..868e0b8a4b85 100644 --- a/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc @@ -35,4 +35,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 34 } -// { dg-error "deleted function" "" { target *-*-* } 475 } +// { dg-error "deleted function" "" { target *-*-* } 481 } diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc index 928ee0a48e90..f8f5a690cf45 100644 --- a/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc @@ -35,4 +35,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 34 } -// { dg-error "deleted function" "" { target *-*-* } 395 } +// { dg-error "deleted function" "" { target *-*-* } 401 } diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc index 5153636e9baa..95b5a1d7d9a5 100644 --- a/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc @@ -34,4 +34,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 33 } -// { dg-error "deleted function" "" { target *-*-* } 394 } +// { dg-error "deleted function" "" { target *-*-* } 400 } -- 2.43.5