diff options
author | cfairles <cfairles@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-10-22 15:27:44 +0000 |
---|---|---|
committer | cfairles <cfairles@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-10-22 15:27:44 +0000 |
commit | a5196aaeefd472abec700261f6ba194ce9deb889 (patch) | |
tree | 1982e8d2183d71a4fdf9f068b3bdf561915edb14 /libstdc++-v3/include/std | |
parent | 6d4987fbfa4079353f8112b251af1c572cb64b95 (diff) | |
download | gcc-a5196aaeefd472abec700261f6ba194ce9deb889.tar.gz |
2008-10-22 Chris Fairles <cfairles@gcc.gnu.org>
* include/std/system_error (is_error_code_enum): Specialize for errc.
(error_category::error_category): Defaulted and protected.
(error_category::~error_category): New, virtual.
(error_category::error_category(const error_category&),
error_category::operator=(const error_category&)): Deleted.
(get_system_category, get_posix_category): Remove (DR 890).
(system_category): External linkage (DR 890).
(posix_category): Remove.
(generic_category): Add. External linkage (DR 890).
(error_code::error_code<>(_ErrorCodeEnum)): Use generic_category.
(error_code::clear, error_code::operator=<>(_ErrorCodeEnum)): Forward to
error_code::assign, use generic_category.
(error_condition::error_condition,
error_condition::error_condition<>(_ErrorConditionEnum)): Use
generic_category.
(error_condition::clear,
error_condition::operator=<>(_ErrorConditionEnum)): Forward to
error_code::assign, use generic_category.
(make_error_code, make_error_condition): Define in namespace std.
* include/std/mutex (unique_lock<>::lock, unique_lock<>::try_lock,
unique_lock<>::try_lock_until<>(duration),
unique_lock<>::try_lock_for<>(duration)): Replace posix_error with errc.
* src/system_error.cc (system_error_category, generic_error_category):
New.
(gnu_error_category): Remove.
(get_system_category, get_posix_category): Remove (DR 890).
(system_category, generic_category): Define.
* src/functexcept.cc (__throw_system_error): Use generic_category.
* config/abi/pre/gnu.ver: Export system_category and generic_category,
remove get_system_category and get_generic_category (DR 890).
* config/os/generic/error_constants.h (posix_errno): Rename to errc, use
enum class type. Fix spelling.
* config/os/mingw32/error_constants.h (posix_errno): Likewise.
* testsuite/19_diagnostics/error_code/cons/1.cc: Use errc and
generic_category.
* testsuite/19_diagnostics/error_code/operators/bool.cc: Use errc.
* testsuite/19_diagnostics/error_code/operators/equal.cc: Likewise.
* testsuite/19_diagnostics/error_code/operators/not_equal.cc: Likewise.
* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Update
dg-error line numbers.
* testsuite/19_diagnostics/error_condition/cons/1.cc: Use
generic_category.
* testsuite/19_diagnostics/error_condition/operators/bool.cc: Use errc.
* testsuite/19_diagnostics/error_condition/operators/equal.cc: Likewise.
* testsuite/19_diagnostics/error_condition/operators/not_equal.cc:
Likewise.
* testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc: New.
* testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc:
Remove using tests since errc is not a namespace.
* testsuite/19_diagnostics/system_error/cons-1.cc: Use errc.
* testsuite/19_diagnostics/system_error/what-4.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc:
Likewise.
* testsuite/30_threads/unique_lock/locking/2.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141297 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/mutex | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/std/system_error | 84 |
2 files changed, 50 insertions, 52 deletions
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex index f3848d09c02..e3922360b3d 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -489,9 +489,9 @@ namespace std lock() { if (!_M_device) - __throw_system_error(posix_error::operation_not_permitted); + __throw_system_error((int)errc::operation_not_permitted); else if (_M_owns) - __throw_system_error(posix_error::resource_deadlock_would_occur); + __throw_system_error((int)errc::resource_deadlock_would_occur); else { _M_device->lock(); @@ -503,9 +503,9 @@ namespace std try_lock() { if (!_M_device) - __throw_system_error(posix_error::operation_not_permitted); + __throw_system_error((int)errc::operation_not_permitted); else if (_M_owns) - __throw_system_error(posix_error::resource_deadlock_would_occur); + __throw_system_error((int)errc::resource_deadlock_would_occur); else { _M_owns = _M_device->try_lock(); @@ -518,9 +518,9 @@ namespace std try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime) { if (!_M_device) - __throw_system_error(posix_error::operation_not_permitted); + __throw_system_error((int)errc::operation_not_permitted); else if (_M_owns) - __throw_system_error(posix_error::resource_deadlock_would_occur); + __throw_system_error((int)errc::resource_deadlock_would_occur); else { _M_owns = _M_device->try_lock_until(__atime); @@ -533,9 +533,9 @@ namespace std try_lock_for(const chrono::duration<_Rep, _Period>& __rtime) { if (!_M_device) - __throw_system_error(posix_error::operation_not_permitted); + __throw_system_error((int)errc::operation_not_permitted); else if (_M_owns) - __throw_system_error(posix_error::resource_deadlock_would_occur); + __throw_system_error((int)errc::resource_deadlock_would_occur); else { _M_owns = _M_device->try_lock_for(__rtime); @@ -547,7 +547,7 @@ namespace std unlock() { if (!_M_owns) - __throw_system_error(posix_error::operation_not_permitted); + __throw_system_error((int)errc::operation_not_permitted); else if (_M_device) { _M_device->unlock(); diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 6a09ebf5272..4a93e5fbbc7 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -57,7 +57,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) struct is_error_code_enum : public false_type { }; template<> - struct is_error_code_enum<posix_error::posix_errno> + struct is_error_code_enum<errc> : public true_type { }; /// is_error_condition_enum @@ -65,14 +65,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) struct is_error_condition_enum : public false_type { }; template<> - struct is_error_condition_enum<posix_error::posix_errno> + struct is_error_condition_enum<errc> : public true_type { }; /// error_category - struct error_category + class error_category { - error_category() { } + protected: + error_category() = default; + + public: + virtual ~error_category() { } + + error_category(const error_category&) = delete; + error_category& operator=(const error_category&) = delete; virtual const char* name() const = 0; @@ -100,19 +107,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) bool operator!=(const error_category& __other) const { return this != &__other; } - - private: - error_category(const error_category&); - - error_category& - operator=(const error_category&); }; - const error_category& get_posix_category(); - const error_category& get_system_category(); - - static const error_category& posix_category = get_posix_category(); - static const error_category& system_category = get_system_category(); + // DR 890. + extern const error_category& system_category; + extern const error_category& generic_category; /// error_code // Implementation-specific error identification @@ -127,7 +126,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _ErrorCodeEnum> error_code(_ErrorCodeEnum __e, typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type* = 0) - : _M_value(__e), _M_cat(&posix_category) + : _M_value(static_cast<int>(__e)), _M_cat(&generic_category) { } void @@ -139,10 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void clear() - { - _M_value = 0; - _M_cat = &system_category; - } + { assign(0, system_category); } // DR 804. template<typename _ErrorCodeEnum> @@ -150,8 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) error_code&>::type operator=(_ErrorCodeEnum __e) { - _M_value = __e; - _M_cat = &posix_category; + assign(static_cast<int>(__e), generic_category); return *this; } @@ -184,7 +179,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const error_category* _M_cat; }; - // 19.4.2.5 non-member functions + // 19.4.2.6 non-member functions + inline error_code + make_error_code(errc __e) + { return error_code(static_cast<int>(__e), generic_category); } + inline bool operator<(const error_code& __lhs, const error_code& __rhs) { @@ -203,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Portable error identification struct error_condition { - error_condition() : _M_value(0), _M_cat(&posix_category) { } + error_condition() : _M_value(0), _M_cat(&generic_category) { } error_condition(int __v, const error_category& __cat) : _M_value(__v), _M_cat(&__cat) { } @@ -212,7 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) error_condition(_ErrorConditionEnum __e, typename enable_if<is_error_condition_enum <_ErrorConditionEnum>::value>::type* = 0) - : _M_value(__e), _M_cat(&posix_category) { } + : _M_value(static_cast<int>(__e)), _M_cat(&generic_category) { } void assign(int __v, const error_category& __cat) @@ -227,17 +226,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) <_ErrorConditionEnum>::value, error_condition&>::type operator=(_ErrorConditionEnum __e) { - _M_value = __e; - _M_cat = &posix_category; + assign(static_cast<int>(__e), generic_category); return *this; } void clear() - { - _M_value = 0; - _M_cat = &posix_category; - } + { assign(0, generic_category); } // 19.4.3.4 observers int @@ -266,7 +261,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const error_category* _M_cat; }; - // 19.4.3.5 non-member functions + // 19.4.3.6 non-member functions + inline error_condition + make_error_condition(errc __e) + { return error_condition(static_cast<int>(__e), generic_category); } + inline bool operator<(const error_condition& __lhs, const error_condition& __rhs) { @@ -275,17 +274,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) && __lhs.value() < __rhs.value())); } - namespace posix_error - { - inline error_code - make_error_code(posix_errno __e) - { return error_code(__e, posix_category); } - - inline error_condition - make_error_condition(posix_errno __e) - { return error_condition(__e, posix_category); } - } - // 19.4.4 Comparison operators inline bool operator==(const error_code& __lhs, const error_code& __rhs) @@ -342,6 +330,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) system_error(error_code __ec, const string& __what) : runtime_error(__what), _M_code(__ec) { } + + /* + * TODO: Add const char* ctors to all exceptions. + * + * system_error(error_code __ec, const char* __what) + * : runtime_error(__what), _M_code(__ec) { } + * + * system_error(int __v, const error_category& __ecat, const char* __what) + * : runtime_error(__what), _M_code(error_code(__v, __ecat)) { } + */ system_error(int __v, const error_category& __ecat) : runtime_error(""), _M_code(error_code(__v, __ecat)) { } |