diff options
| author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-16 21:55:00 +0000 |
|---|---|---|
| committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-16 21:55:00 +0000 |
| commit | 9539daa08a73c37498c5b5f06389dddd0fb86946 (patch) | |
| tree | db696e79edd0beb18fbe3903b5746d4243fb7897 /libstdc++-v3/include/std/system_error | |
| parent | 35415f9d4790d901be97ce576966fc54bfa0220a (diff) | |
| download | ppe42-gcc-9539daa08a73c37498c5b5f06389dddd0fb86946.tar.gz ppe42-gcc-9539daa08a73c37498c5b5f06389dddd0fb86946.zip | |
2008-05-16 Benjamin Kosnik <bkoz@redhat.com>
* include/std/system_error: Align to current draft specifications.
* src/system_error.cc: Same.
* src/functexcept.cc: Adjust for corrected system_error construction.
* include/std/ostream: Adjust error_code inserter.
* acinclude.m4 (GLIBCXX_CHECK_SYSTEM_ERROR): Remove sys_nerr test.
* config/abi/pre/gnu.ver: Add new exports.
* testsuite/util/testsuite_error.h: Consolidate error testing
utilities here.
* testsuite/19_diagnostics/error_code/cons/1.cc: Use
testsuite_error, adjust line numbers and constructor calls.
* testsuite/19_diagnostics/error_code/operators/equal.cc: Same.
* testsuite/19_diagnostics/error_code/operators/not_equal.cc: Same.
* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Same.
* testsuite/19_diagnostics/error_category/cons/default.cc: Same.
* testsuite/19_diagnostics/error_category/operators/equal.cc: Same.
* testsuite/19_diagnostics/error_category/operators/not_equal.cc: Same.
* testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc:
Same.
* testsuite/19_diagnostics/system_error/cons-1.cc: Same.
* testsuite/19_diagnostics/system_error/what-1.cc: Same.
* testsuite/19_diagnostics/system_error/what-2.cc: Same.
* testsuite/19_diagnostics/system_error/what-big.cc: Same.
* testsuite/19_diagnostics/system_error/what-3.cc: Same.
* testsuite/19_diagnostics/system_error/what-4.cc: Same.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135446 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/system_error')
| -rw-r--r-- | libstdc++-v3/include/std/system_error | 212 |
1 files changed, 185 insertions, 27 deletions
diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 5081e3f11ec..ac3b1f75b61 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -47,17 +47,52 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - class system_error; class error_code; + class error_condition; class error_category; + class system_error; + + /// is_error_code_enum + template<typename _T> + struct is_error_code_enum : public false_type { }; + + template<> + struct is_error_code_enum<posix_error::posix_errno> + : public true_type { }; + + /// is_error_condition_enum + template<typename _T> + struct is_error_condition_enum : public false_type { }; + + template<> + struct is_error_condition_enum<posix_error::posix_errno> + : public true_type { }; - extern const error_category& system_category; /// error_category struct error_category { error_category() { } + virtual const char* + name() const = 0; + + virtual string + message(int) const = 0; + + virtual error_condition + default_error_condition(int __i) const; + + virtual bool + equivalent(int __i, const error_condition& __cond) const; + + virtual bool + equivalent(const error_code& __code, int __i) const; + + bool + operator<(const error_category& __other) const + { return less<const error_category*>()(this, &__other); } + bool operator==(const error_category& __other) const { return this == &__other; } @@ -66,12 +101,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator!=(const error_category& __other) const { return this != &__other; } - virtual posix_error::posix_errno - posix(int __v) const = 0; - - virtual const string& - name() const = 0; - private: error_category(const error_category&); @@ -79,40 +108,59 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator=(const error_category&); }; + const error_category& get_posix_category(); + const error_category& get_system_category(); + + static const error_category& system_category = get_system_category(); + static const error_category& native_category = get_posix_category(); + /// error_code + // Implementation-specific error identification struct error_code { - error_code() throw() + error_code() : _M_value(0), _M_cat(&system_category) { } - error_code(int __v, const error_category& __cat) throw() + error_code(int __v, const error_category& __cat) : _M_value(__v), _M_cat(&__cat) { } - error_code(posix_error::posix_errno __v) - : _M_value(__v), _M_cat(&system_category) { } + template<typename _ErrorCodeEnum> + error_code(_ErrorCodeEnum __e, + typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type* = 0) + : _M_value(__e), _M_cat(&system_category) + { } void - assign(int __v, const error_category& __cat) throw() + assign(int __v, const error_category& __cat) { _M_value = __v; _M_cat = &__cat; } void - clear() throw() + clear() { _M_value = 0; _M_cat = &system_category; - } + } + + template<typename _ErrorCodeEnum> + typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type& + operator=(_ErrorCodeEnum __e) + { _M_value = __e; } int - value() const throw() { return _M_value; } + value() const { return _M_value; } const error_category& category() const { return *_M_cat; } - posix_error::posix_errno - posix() const throw() { return this->category().posix(_M_value); } + error_condition + default_error_condition() const; + + string + message() const + { return category().message(value()); } // Safe bool idiom. // explicit operator bool() const throw() @@ -121,20 +169,127 @@ _GLIBCXX_BEGIN_NAMESPACE(std) static void __not_bool_type() { } - operator __bool_type() const throw() + operator __bool_type() const { return _M_value != 0 ? &__not_bool_type : false; } - bool operator==(const error_code& __other) const - { return value() == __other.value() && category() == __other.category(); } - - bool operator!=(const error_code& __other) const - { return !(this == &__other); } - private: int _M_value; const error_category* _M_cat; }; + error_code + make_error_code(posix_error::posix_errno); + + // 19.4.2.5 non-member functions + bool operator<(const error_code& lhs, const error_code& rhs); + + template<typename charT, typename traits> + basic_ostream<charT,traits>& + operator<<(basic_ostream<charT,traits>& os, const error_code& __code); + + + /// error_condition + // Portable error identification + struct error_condition + { + error_condition() : _M_value(0), _M_cat(system_category) { } + + error_condition(int __v, const error_category& __cat) + : _M_value(__v), _M_cat(__cat) { } + + template<typename _ErrorEnum> + error_condition(typename enable_if<is_error_condition_enum<_ErrorEnum>::value, _ErrorEnum>::type __v) : _M_value(__v), _M_cat(system_category) { } + + void + assign(int val, const error_category& cat); + + template<typename _ErrorEnum> + error_condition& + operator=(typename enable_if<is_error_condition_enum<_ErrorEnum>::value, _ErrorEnum>::type __v) + { _M_value = __v; } + + void + clear(); + + // 19.4.3.4 observers + int + value() const { return _M_value; } + + const error_category& + category() const { return _M_cat; } + + string + message() const + { return category().message(value()); } + + // Safe bool idiom. + // explicit operator bool() const throw() + // { return _M_value != 0; } + typedef void (*__bool_type)(); + + static void __not_bool_type() { } + + operator __bool_type() const + { return _M_value != 0 ? &__not_bool_type : false; } + + private: + int _M_value; + const error_category& _M_cat; + }; + + error_condition + make_error_condition(posix_error::posix_errno); + + // 19.4.3.5 non-member functions + inline bool + operator<(const error_condition& lhs, const error_condition& rhs) + { + bool __t1 = lhs.category() < rhs.category(); + bool __t2 = lhs.category() == rhs.category() && lhs.value() < rhs.value(); + return __t1 || __t2; + } + + // 19.4.4 Comparison operators + inline bool + operator==(const error_code& lhs, const error_code& rhs) + { return lhs.category() == rhs.category() && lhs.value() == rhs.value(); } + + inline bool + operator==(const error_code& lhs, const error_condition& rhs) + { + bool __t1 = lhs.category().equivalent(lhs.value(), rhs); + bool __t2 = rhs.category().equivalent(lhs, rhs.value()); + return __t1 || __t2; + } + + inline bool + operator==(const error_condition& lhs, const error_code& rhs) + { + bool __t1 = rhs.category().equivalent(rhs.value(), lhs); + bool __t2 = lhs.category().equivalent(rhs, lhs.value()); + return __t1 || __t2; + } + + inline bool + operator==(const error_condition& lhs, const error_condition& rhs) + { return lhs.category() == rhs.category() && lhs.value() == rhs.value(); } + + inline bool + operator!=(const error_code& lhs, const error_code& rhs) + { return !(lhs == rhs); } + + inline bool + operator!=(const error_code& lhs, const error_condition& rhs) + { return !(lhs == rhs); } + + inline bool + operator!=(const error_condition& lhs, const error_code& rhs) + { return !(lhs == rhs); } + + inline bool + operator!=(const error_condition& lhs, const error_condition& rhs) + { return !(lhs == rhs); } + /// Thrown to indicate error code of underlying system. class system_error : public std::runtime_error { @@ -145,10 +300,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) system_error(error_code __ec = error_code()) : runtime_error(""), _M_code(__ec) { } - system_error(const string& __what, error_code __ec = error_code()) + system_error(error_code __ec, const string& __what) : runtime_error(__what), _M_code(__ec) { } - system_error(const string& __what, int __v, const error_category& __ecat) + system_error(int __v, const error_category& __ecat) + : runtime_error(""), _M_code(error_code(__v, __ecat)) { } + + system_error(int __v, const error_category& __ecat, const string& __what) : runtime_error(__what), _M_code(error_code(__v, __ecat)) { } virtual ~system_error() throw(); |

