Index: src/system_error.cc =================================================================== --- src/system_error.cc (revision 141102) +++ src/system_error.cc (working copy) @@ -36,15 +36,12 @@ namespace { using std::string; - - struct gnu_error_category : public std::error_category + + struct generic_error_category : public std::error_category { virtual const char* name() const - { - const char* s = "GNU"; - return s; - } + { return "generic"; } virtual string message(int i) const @@ -55,16 +52,32 @@ } }; - const gnu_error_category gnu_category; + struct system_error_category : public std::error_category + { + virtual const char* + name() const + { return "system"; } + + virtual string + message(int i) const + { + // XXX locale issues: how does one get or set loc. + // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) + return string(strerror(i)); + } + }; + + const generic_error_category generic_category; + const system_error_category system_category; } _GLIBCXX_BEGIN_NAMESPACE(std) const error_category& - get_posix_category() { return gnu_category; } + get_generic_category() { return generic_category; } const error_category& - get_system_category() { return gnu_category; } + get_system_category() { return system_category; } system_error::~system_error() throw() { } Index: include/std/system_error =================================================================== --- include/std/system_error (revision 141102) +++ include/std/system_error (working copy) @@ -57,7 +57,7 @@ struct is_error_code_enum : public false_type { }; template<> - struct is_error_code_enum + struct is_error_code_enum : public true_type { }; /// is_error_condition_enum @@ -65,15 +65,22 @@ struct is_error_condition_enum : public false_type { }; template<> - struct is_error_condition_enum + struct is_error_condition_enum : 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,13 @@ 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_generic_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(); + static const error_category& generic_category = get_generic_category(); /// error_code // Implementation-specific error identification @@ -127,7 +128,7 @@ template error_code(_ErrorCodeEnum __e, typename enable_if::value>::type* = 0) - : _M_value(__e), _M_cat(&posix_category) + :_M_value(static_cast(__e)), _M_cat(&generic_category) { } void @@ -150,8 +151,8 @@ error_code&>::type operator=(_ErrorCodeEnum __e) { - _M_value = __e; - _M_cat = &posix_category; + _M_value = static_cast(__e); + _M_cat = &generic_category; return *this; } @@ -184,7 +185,11 @@ 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(__e), generic_category); } + inline bool operator<(const error_code& __lhs, const error_code& __rhs) { @@ -203,7 +208,7 @@ // 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 +217,7 @@ error_condition(_ErrorConditionEnum __e, typename enable_if::value>::type* = 0) - : _M_value(__e), _M_cat(&posix_category) { } + : _M_value(static_cast(__e)), _M_cat(&generic_category) { } void assign(int __v, const error_category& __cat) @@ -227,8 +232,8 @@ <_ErrorConditionEnum>::value, error_condition&>::type operator=(_ErrorConditionEnum __e) { - _M_value = __e; - _M_cat = &posix_category; + _M_value = static_cast(__e); + _M_cat = &generic_category; return *this; } @@ -236,7 +241,7 @@ clear() { _M_value = 0; - _M_cat = &posix_category; + _M_cat = &generic_category; } // 19.4.3.4 observers @@ -266,7 +271,11 @@ 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(__e), generic_category); } + inline bool operator<(const error_condition& __lhs, const error_condition& __rhs) { @@ -275,17 +284,6 @@ && __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 +340,16 @@ 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)) { } Index: include/std/mutex =================================================================== --- include/std/mutex (revision 141102) +++ include/std/mutex (working copy) @@ -489,9 +489,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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(); Index: testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc =================================================================== --- testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc (revision 141102) +++ testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc (working copy) @@ -33,7 +33,7 @@ wchar_t buf[64]; error_code e1; - error_code e2(posix_error::bad_address); + error_code e2(errc::bad_address); wstring s, s1, s2; { Index: testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc =================================================================== --- testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc (revision 141102) +++ testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc (working copy) @@ -33,7 +33,7 @@ char buf[64]; error_code e1; - error_code e2(posix_error::bad_address); + error_code e2(errc::bad_address); string s, s1, s2; { Index: testsuite/19_diagnostics/error_condition/cons/1.cc =================================================================== --- testsuite/19_diagnostics/error_condition/cons/1.cc (revision 141102) +++ testsuite/19_diagnostics/error_condition/cons/1.cc (working copy) @@ -28,7 +28,7 @@ // 1 std::error_condition e1; VERIFY( e1.value() == 0 ); - VERIFY( e1.category() == std::posix_category ); + VERIFY( e1.category() == std::system_category ); // 2 const __gnu_test::test_category cat; @@ -37,9 +37,9 @@ VERIFY( e2.category() == cat ); // 3 - std::error_condition e3(std::posix_error::operation_not_supported); - VERIFY( e3.value() == int(std::posix_error::operation_not_supported) ); - VERIFY( e3.category() == std::posix_category ); + std::error_condition e3(std::errc::operation_not_supported); + VERIFY( e3.value() == int(std::errc::operation_not_supported) ); + VERIFY( e3.category() == std::system_category ); } int main() Index: testsuite/19_diagnostics/error_condition/operators/bool.cc =================================================================== --- testsuite/19_diagnostics/error_condition/operators/bool.cc (revision 141102) +++ testsuite/19_diagnostics/error_condition/operators/bool.cc (working copy) @@ -34,7 +34,7 @@ } // 2 - std::error_condition e2(std::posix_error::operation_not_supported); + std::error_condition e2(std::errc::operation_not_supported); if (e2) { VERIFY( true ); Index: testsuite/19_diagnostics/error_condition/operators/equal.cc =================================================================== --- testsuite/19_diagnostics/error_condition/operators/equal.cc (revision 141102) +++ testsuite/19_diagnostics/error_condition/operators/equal.cc (working copy) @@ -27,7 +27,7 @@ bool test __attribute__((unused)) = true; std::error_condition e1; - std::error_condition e2(std::posix_error::operation_not_supported); + std::error_condition e2(std::errc::operation_not_supported); VERIFY( e1 == e1 ); VERIFY( !(e1 == e2) ); Index: testsuite/19_diagnostics/error_condition/operators/not_equal.cc =================================================================== --- testsuite/19_diagnostics/error_condition/operators/not_equal.cc (revision 141102) +++ testsuite/19_diagnostics/error_condition/operators/not_equal.cc (working copy) @@ -27,7 +27,7 @@ bool test __attribute__((unused)) = true; std::error_condition e1; - std::error_condition e2(std::posix_error::operation_not_supported); + std::error_condition e2(std::errc::operation_not_supported); VERIFY( !(e1 != e1) ); VERIFY( e1 != e2 ); Index: testsuite/19_diagnostics/error_code/cons/1.cc =================================================================== --- testsuite/19_diagnostics/error_code/cons/1.cc (revision 141102) +++ testsuite/19_diagnostics/error_code/cons/1.cc (working copy) @@ -38,9 +38,9 @@ VERIFY( e2.category() == cat ); // 3 - std::error_code e3(std::posix_error::operation_not_supported); - VERIFY( e3.value() == int(std::posix_error::operation_not_supported) ); - VERIFY( e3.category() == std::posix_category ); + std::error_code e3(std::errc::operation_not_supported); + VERIFY( e3.value() == int(std::errc::operation_not_supported) ); + VERIFY( e3.category() == std::system_category ); return 0; } Index: testsuite/19_diagnostics/error_code/operators/bool.cc =================================================================== --- testsuite/19_diagnostics/error_code/operators/bool.cc (revision 141102) +++ testsuite/19_diagnostics/error_code/operators/bool.cc (working copy) @@ -35,7 +35,7 @@ } // 2 - std::error_code e2(std::posix_error::operation_not_supported); + std::error_code e2(std::errc::operation_not_supported); if (e2) { VERIFY( true ); Index: testsuite/19_diagnostics/error_code/operators/equal.cc =================================================================== --- testsuite/19_diagnostics/error_code/operators/equal.cc (revision 141102) +++ testsuite/19_diagnostics/error_code/operators/equal.cc (working copy) @@ -28,7 +28,7 @@ bool test __attribute__((unused)) = true; std::error_code e1; - std::error_code e2(std::posix_error::operation_not_supported); + std::error_code e2(std::errc::operation_not_supported); VERIFY( e1 == e1 ); VERIFY( !(e1 == e2) ); Index: testsuite/19_diagnostics/error_code/operators/not_equal.cc =================================================================== --- testsuite/19_diagnostics/error_code/operators/not_equal.cc (revision 141102) +++ testsuite/19_diagnostics/error_code/operators/not_equal.cc (working copy) @@ -28,7 +28,7 @@ bool test __attribute__((unused)) = true; std::error_code e1; - std::error_code e2(std::posix_error::operation_not_supported); + std::error_code e2(std::errc::operation_not_supported); VERIFY( !(e1 != e1) ); VERIFY( e1 != e2 ); Index: testsuite/19_diagnostics/error_category/cons/copy_neg.cc =================================================================== --- testsuite/19_diagnostics/error_category/cons/copy_neg.cc (revision 141102) +++ testsuite/19_diagnostics/error_category/cons/copy_neg.cc (working copy) @@ -33,7 +33,7 @@ return 0; } -// { dg-error "is private" "" { target *-*-* } 105 } -// { dg-error "within this context" "" { target *-*-* } 40 } +// { dg-error "deleted function" "" { target *-*-* } 81 } +// { dg-error "used here" "" { target *-*-* } 40 } // { dg-error "first required here" "" { target *-*-* } 31 } // { dg-excess-errors "copy constructor" } Index: testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc =================================================================== --- testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc (revision 141102) +++ testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc (working copy) @@ -28,134 +28,133 @@ using std::error_category; using std::system_category; - using std::posix_error::posix_errno; - using std::posix_error::address_family_not_supported; - using std::posix_error::address_in_use; - using std::posix_error::address_not_available; - using std::posix_error::already_connected; - using std::posix_error::argument_list_too_long; - using std::posix_error::argument_out_of_domain; - using std::posix_error::bad_address; - using std::posix_error::bad_file_descriptor; + using std::errc::address_family_not_supported; + using std::errc::address_in_use; + using std::errc::address_not_available; + using std::errc::already_connected; + using std::errc::argument_list_too_long; + using std::errc::argument_out_of_domain; + using std::errc::bad_address; + using std::errc::bad_file_descriptor; #ifdef _GLIBCXX_HAVE_EBADMSG - using std::posix_error::bad_message; + using std::errc::bad_message; #endif - using std::posix_error::broken_pipe; - using std::posix_error::connection_aborted; - using std::posix_error::connection_already_in_progress; - using std::posix_error::connection_refused; - using std::posix_error::connection_reset; - using std::posix_error::cross_device_link; - using std::posix_error::destination_address_required; - using std::posix_error::device_or_resource_busy; - using std::posix_error::directory_not_empty; - using std::posix_error::executable_format_error; - using std::posix_error::file_exists; - using std::posix_error::file_too_large; - using std::posix_error::filename_too_long; - using std::posix_error::function_not_supported; - using std::posix_error::host_unreachable; + using std::errc::broken_pipe; + using std::errc::connection_aborted; + using std::errc::connection_already_in_progress; + using std::errc::connection_refused; + using std::errc::connection_reset; + using std::errc::cross_device_link; + using std::errc::destination_address_required; + using std::errc::device_or_resource_busy; + using std::errc::directory_not_empty; + using std::errc::executable_format_error; + using std::errc::file_exists; + using std::errc::file_too_large; + using std::errc::filename_too_long; + using std::errc::function_not_supported; + using std::errc::host_unreachable; #ifdef _GLIBCXX_HAVE_EIDRM - using std::posix_error::identifier_removed; + using std::errc::identifier_removed; #endif - using std::posix_error::illegal_byte_sequence; - using std::posix_error::inappropriate_io_control_operation; - using std::posix_error::interrupted; - using std::posix_error::invalid_argument; - using std::posix_error::invalid_seek; - using std::posix_error::io_error; - using std::posix_error::is_a_directory; - using std::posix_error::message_size; - using std::posix_error::network_down; - using std::posix_error::network_reset; - using std::posix_error::network_unreachable; - using std::posix_error::no_buffer_space; - using std::posix_error::no_child_process; + using std::errc::illegal_byte_sequence; + using std::errc::inappropriate_io_control_operation; + using std::errc::interrupted; + using std::errc::invalid_argument; + using std::errc::invalid_seek; + using std::errc::io_error; + using std::errc::is_a_directory; + using std::errc::message_size; + using std::errc::network_down; + using std::errc::network_reset; + using std::errc::network_unreachable; + using std::errc::no_buffer_space; + using std::errc::no_child_process; #ifdef _GLIBCXX_HAVE_ENOLINK - using std::posix_error::no_link; + using std::errc::no_link; #endif - using std::posix_error::no_lock_available; + using std::errc::no_lock_available; #ifdef _GLIBCXX_HAVE_ENODATA - using std::posix_error::no_message_available; + using std::errc::no_message_available; #endif - using std::posix_error::no_message; - using std::posix_error::no_posix_equivalent; - using std::posix_error::no_protocol_option; - using std::posix_error::no_space_on_device; + using std::errc::no_message; + using std::errc::no_posix_equivalent; + using std::errc::no_protocol_option; + using std::errc::no_space_on_device; #ifdef _GLIBCXX_HAVE_ENOSR - using std::posix_error::no_stream_resources; + using std::errc::no_stream_resources; #endif - using std::posix_error::no_such_device_or_address; - using std::posix_error::no_such_device; - using std::posix_error::no_such_file_or_directory; - using std::posix_error::no_such_process; - using std::posix_error::not_a_directory; - using std::posix_error::not_a_socket; + using std::errc::no_such_device_or_address; + using std::errc::no_such_device; + using std::errc::no_such_file_or_directory; + using std::errc::no_such_process; + using std::errc::not_a_directory; + using std::errc::not_a_socket; #ifdef _GLIBCXX_HAVE_ENOSTR - using std::posix_error::not_a_stream; + using std::errc::not_a_stream; #endif - using std::posix_error::not_connected; - using std::posix_error::not_enough_memory; - using std::posix_error::not_supported; + using std::errc::not_connected; + using std::errc::not_enough_memory; + using std::errc::not_supported; #ifdef _GLIBCXX_HAVE_ECANCELED - using std::posix_error::operation_canceled; + using std::errc::operation_canceled; #endif - using std::posix_error::operation_in_progress; - using std::posix_error::operation_not_permitted; - using std::posix_error::operation_not_supported; - using std::posix_error::operation_would_block; + using std::errc::operation_in_progress; + using std::errc::operation_not_permitted; + using std::errc::operation_not_supported; + using std::errc::operation_would_block; #ifdef _GLIBCXX_HAVE_EOWNERDEAD - using std::posix_error::owner_dead; + using std::errc::owner_dead; #endif - using std::posix_error::permission_denied; + using std::errc::permission_denied; #ifdef _GLIBCXX_HAVE_EPROTO - using std::posix_error::protocol_error; + using std::errc::protocol_error; #endif - using std::posix_error::protocol_not_supported; - using std::posix_error::read_only_file_system; - using std::posix_error::resource_deadlock_would_occur; - using std::posix_error::resource_unavailable_try_again; - using std::posix_error::result_out_of_range; + using std::errc::protocol_not_supported; + using std::errc::read_only_file_system; + using std::errc::resource_deadlock_would_occur; + using std::errc::resource_unavailable_try_again; + using std::errc::result_out_of_range; #ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE - using std::posix_error::state_not_recoverable; + using std::errc::state_not_recoverable; #endif #ifdef _GLIBCXX_HAVE_ETIME - using std::posix_error::stream_timeout; + using std::errc::stream_timeout; #endif #ifdef _GLIBCXX_HAVE_ETXTBSY - using std::posix_error::text_file_busy; + using std::errc::text_file_busy; #endif - using std::posix_error::timed_out; - using std::posix_error::too_many_files_open_in_system; - using std::posix_error::too_many_files_open; - using std::posix_error::too_many_links; - using std::posix_error::too_many_synbolic_link_levels; + using std::errc::timed_out; + using std::errc::too_many_files_open_in_system; + using std::errc::too_many_files_open; + using std::errc::too_many_links; + using std::errc::too_many_synbolic_link_levels; #ifdef _GLIBCXX_HAVE_EOVERFLOW - using std::posix_error::value_too_large; + using std::errc::value_too_large; #endif - using std::posix_error::wrong_protocol_type; + using std::errc::wrong_protocol_type; } Index: testsuite/19_diagnostics/system_error/cons-1.cc =================================================================== --- testsuite/19_diagnostics/system_error/cons-1.cc (revision 141102) +++ testsuite/19_diagnostics/system_error/cons-1.cc (working copy) @@ -27,7 +27,7 @@ { bool test __attribute__((unused)) = true; const std::string s("too late: boulangerie out of pain au raisin"); - const std::error_code e(std::posix_error::operation_not_supported); + const std::error_code e(std::errc::operation_not_supported); // 1 { Index: testsuite/19_diagnostics/system_error/what-4.cc =================================================================== --- testsuite/19_diagnostics/system_error/what-4.cc (revision 141102) +++ testsuite/19_diagnostics/system_error/what-4.cc (working copy) @@ -32,7 +32,7 @@ bool test __attribute__((unused)) = true; std::string s("after nine thirty, this request cannot be met"); - std::system_error obj = std::system_error(std::posix_error::invalid_argument, s); + std::system_error obj = std::system_error(std::errc::invalid_argument, s); std::string s1(obj.what()); std::string s2(obj.what()); VERIFY( s1 == s2 ); Index: testsuite/30_threads/unique_lock/locking/2.cc =================================================================== --- testsuite/30_threads/unique_lock/locking/2.cc (revision 141102) +++ testsuite/30_threads/unique_lock/locking/2.cc (working copy) @@ -54,7 +54,7 @@ catch (const std::system_error& ex) { VERIFY( ex.code() == std::error_code( - std::posix_error::operation_not_permitted) ); + std::errc::operation_not_permitted) ); } catch (...) { @@ -91,7 +91,7 @@ catch (const std::system_error& ex) { VERIFY( ex.code() == std::error_code( - std::posix_error::resource_deadlock_would_occur) ); + std::errc::resource_deadlock_would_occur) ); } catch (...) { Index: config/os/mingw32/error_constants.h =================================================================== --- config/os/mingw32/error_constants.h (revision 141102) +++ config/os/mingw32/error_constants.h (working copy) @@ -41,10 +41,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) -namespace posix_error { // Most of the commented-out error codes are socket-related and could be // replaced by Winsock WSA-prefixed equivalents. - enum posix_errno + enum class errc { // address_family_not_supported = EAFNOSUPPORT, // address_in_use = EADDRINUSE, @@ -126,7 +125,6 @@ // wrong_protocol_type = EPROTOTYPE, no_posix_equivalent = 1L << 16 }; -} _GLIBCXX_END_NAMESPACE Index: config/os/generic/error_constants.h =================================================================== --- config/os/generic/error_constants.h (revision 141102) +++ config/os/generic/error_constants.h (working copy) @@ -40,9 +40,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) -namespace posix_error -{ - enum posix_errno + enum class errc { address_family_not_supported = EAFNOSUPPORT, address_in_use = EADDRINUSE, @@ -177,7 +175,6 @@ wrong_protocol_type = EPROTOTYPE, no_posix_equivalent = 1L << 16 }; -} _GLIBCXX_END_NAMESPACE Index: config/abi/pre/gnu.ver =================================================================== --- config/abi/pre/gnu.ver (revision 141102) +++ config/abi/pre/gnu.ver (working copy) @@ -922,7 +922,7 @@ _ZNSt6threadD2Ev; # system_error - _ZSt18get_posix_categoryv; + _ZSt20get_generic_categoryv; _ZSt19get_system_categoryv; _ZNKSt10error_code23default_error_conditionEv;