From 70593ad2f1664cd978d11da4ecc01f05babe0c59 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Fri, 16 May 2008 21:55:00 +0000 Subject: [PATCH] system_error: Align to current draft specifications. 2008-05-16 Benjamin Kosnik * 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. From-SVN: r135446 --- libstdc++-v3/ChangeLog | 28 +++ libstdc++-v3/acinclude.m4 | 2 +- libstdc++-v3/config/abi/pre/gnu.ver | 13 +- libstdc++-v3/include/std/ostream | 2 +- libstdc++-v3/include/std/system_error | 212 +++++++++++++++--- libstdc++-v3/src/functexcept.cc | 2 +- libstdc++-v3/src/system_error.cc | 48 ++-- .../error_category/cons/copy_neg.cc | 27 +-- .../error_category/cons/default.cc | 31 +-- .../error_category/operators/equal.cc | 31 +-- .../error_category/operators/not_equal.cc | 31 +-- .../19_diagnostics/error_code/cons/1.cc | 21 +- .../error_code/operators/equal.cc | 21 +- .../error_code/operators/not_equal.cc | 21 +- .../19_diagnostics/system_error/cons-1.cc | 6 +- .../system_error/cons_virtual_derivation.cc | 2 +- .../19_diagnostics/system_error/what-1.cc | 20 +- .../19_diagnostics/system_error/what-2.cc | 4 +- .../19_diagnostics/system_error/what-3.cc | 6 +- .../19_diagnostics/system_error/what-4.cc | 4 +- .../19_diagnostics/system_error/what-big.cc | 4 +- libstdc++-v3/testsuite/util/testsuite_error.h | 66 ++++++ 22 files changed, 366 insertions(+), 236 deletions(-) create mode 100644 libstdc++-v3/testsuite/util/testsuite_error.h diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 88a038d1b163..1a32e5572e45 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2008-05-16 Benjamin Kosnik + + * 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. + 2008-05-15 Bernd Schmidt * configure.ac: Don't check AC_LIBTOOL_DLOPEN if using newlib. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 022548b07db6..db3c7b19b252 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -1327,7 +1327,7 @@ AC_DEFUN([GLIBCXX_CHECK_SYSTEM_ERROR], [ m4_pushdef([n_syserr], [1])dnl m4_foreach([syserr], [EOWNERDEAD, ENOTRECOVERABLE, ENOLINK, EPROTO, ENODATA, - ENOSR, ENOSTR, ETIME, sys_nerr, EBADMSG, ECANCELED, + ENOSR, ENOSTR, ETIME, EBADMSG, ECANCELED, EOVERFLOW, ENOTSUP, EIDRM, ETXTBSY], [m4_pushdef([SYSERR], m4_toupper(syserr))dnl AC_MSG_CHECKING([for syserr]) diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 48b8cfd0aae0..225e6e5c71fd 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -70,7 +70,9 @@ GLIBCXX_3.4 { # std::[d-g]*; std::d[a-d]*; std::d[f-z]*; - std::e*; + std::e[a-q]*; + std::error[^_]*; + std::e[s-z]*; std::gslice*; std::h[^a]*; std::i[a-n]*; @@ -854,7 +856,14 @@ GLIBCXX_3.4.11 { _ZNSt18condition_variableD2Ev; # system_error - _ZSt15system_category; + _ZSt18get_posix_categoryv; + _ZSt19get_system_categoryv; + + _ZNKSt10error_code23default_error_conditionEv; + _ZNKSt14error_category23default_error_conditionEi; + + _ZNKSt14error_category10equivalentERKSt10error_codei; + _ZNKSt14error_category10equivalentEiRKSt15error_condition; _ZTISt14error_category; _ZTSSt14error_category; diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index ffbb0e121f41..c0120fa2f053 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -539,7 +539,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template inline basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __out, const error_code& __e) - { return (__out << __e.category().name().c_str() << ':' << __e.value()); } + { return (__out << __e.category().name() << ':' << __e.value()); } #endif // [27.6.2.7] standard basic_ostream manipulators diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 5081e3f11ec3..ac3b1f75b61f 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 + struct is_error_code_enum : public false_type { }; + + template<> + struct is_error_code_enum + : public true_type { }; + + /// is_error_condition_enum + template + struct is_error_condition_enum : public false_type { }; + + template<> + struct is_error_condition_enum + : 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()(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 + error_code(_ErrorCodeEnum __e, + typename enable_if::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 enable_if::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 + basic_ostream& + operator<<(basic_ostream& 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 + error_condition(typename enable_if::value, _ErrorEnum>::type __v) : _M_value(__v), _M_cat(system_category) { } + + void + assign(int val, const error_category& cat); + + template + error_condition& + operator=(typename enable_if::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(); diff --git a/libstdc++-v3/src/functexcept.cc b/libstdc++-v3/src/functexcept.cc index f77bb0d29cda..95b65bb326b9 100644 --- a/libstdc++-v3/src/functexcept.cc +++ b/libstdc++-v3/src/functexcept.cc @@ -98,7 +98,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void __throw_system_error(const char* __s) - { throw system_error(_(__s)); } + { throw system_error(error_code(), _(__s)); } void __throw_system_error(int __i) diff --git a/libstdc++-v3/src/system_error.cc b/libstdc++-v3/src/system_error.cc index 81e73fcc7f99..6724ef75a1f2 100644 --- a/libstdc++-v3/src/system_error.cc +++ b/libstdc++-v3/src/system_error.cc @@ -1,6 +1,6 @@ // implementation file -// Copyright (C) 2007 +// Copyright (C) 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -35,27 +35,23 @@ namespace { + using std::string; + struct gnu_error_category : public std::error_category { - virtual const std::string& + virtual const char* name() const { - static const std::string category("GNU"); - return category; + const char* s = "GNU"; + return s; } - virtual std::posix_error::posix_errno - posix(int __v) const + virtual string + message(int i) const { -#ifdef _GLIBCXX_HAVE_SYS_NERR - const int last_errorno = sys_nerr; -#else - const int last_errorno = std::numeric_limits::max(); -#endif - if (__v > 0 && __v <= last_errorno) - return std::posix_error::posix_errno(__v); - else - return std::posix_error::no_posix_equivalent; + // XXX locale issues: how does one get or set loc. + // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) + return string(strerror(i)); } }; @@ -64,8 +60,28 @@ namespace _GLIBCXX_BEGIN_NAMESPACE(std) - const error_category& system_category = gnu_category; + const error_category& + get_posix_category() { return gnu_category; } + + const error_category& + get_system_category() { return gnu_category; } system_error::~system_error() throw() { } + error_condition + error_category::default_error_condition(int __i) const + { return error_condition(__i, *this); } + + bool + error_category::equivalent(int __i, const error_condition& __cond) const + { return default_error_condition(__i) == __cond; } + + bool + error_category::equivalent(const error_code& __code, int __i) const + { return *this == __code.category() && __code.value() == __i; } + + error_condition + error_code::default_error_condition() const + { return category().default_error_condition(value()); } + _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/copy_neg.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/copy_neg.cc index 5a8ec640fefe..b7635fee4c00 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/copy_neg.cc @@ -2,7 +2,7 @@ // { dg-do compile } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -21,24 +21,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; -} +#include int main() { @@ -50,7 +33,7 @@ int main() return 0; } -// { dg-error "is private" "" { target *-*-* } 76 } -// { dg-error "within this context" "" { target *-*-* } 29 } -// { dg-error "first required here" "" { target *-*-* } 48 } +// { dg-error "is private" "" { target *-*-* } 105 } +// { dg-error "within this context" "" { target *-*-* } 41 } +// { dg-error "first required here" "" { target *-*-* } 31 } // { dg-excess-errors "copy constructor" } diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/default.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/default.cc index 1072cc63c674..50c465161317 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/default.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/default.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,34 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; - - struct test_derived_category : public test_category - { - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_derived_category"); - return s; - } - }; -} +#include int main() { diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc index 7b8a19cd7e33..b900521cb214 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,34 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; - - struct test_derived_category : public test_category - { - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_derived_category"); - return s; - } - }; -} +#include int main() { diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/not_equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/not_equal.cc index 043c8a207a30..eab9940d0567 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/not_equal.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/not_equal.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,34 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; - - struct test_derived_category : public test_category - { - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_derived_category"); - return s; - } - }; -} +#include int main() { diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc index ea1316d067af..8ba68d645e19 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,24 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; -} +#include int main() { diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc index a98ed9023a09..a8fc65c4c319 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,24 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; -} +#include // unspecified bool operator positive tests int main() diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc index 00153456403b..d5d75553bf57 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-08-22 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -20,24 +20,7 @@ // USA. #include -#include - -namespace __gnu_test -{ - struct test_category : public std::error_category - { - virtual std::posix_error::posix_errno - posix(int __v) const - { return std::posix_error::posix_errno(__v); } - - virtual const std::string& - name() const - { - static std::string s("__gnu_test::test_category"); - return s; - } - }; -} +#include // unspecified bool operator positive tests int main() diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc index 2885dad27235..9fc24f1f25d7 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2007-06-05 Benjamin Kosnik -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -31,14 +31,14 @@ int main() // 1 { - std::system_error err1(s, e); + std::system_error err1(e, s); VERIFY( err1.code() == e ); VERIFY( std::strcmp(err1.runtime_error::what(), s.c_str()) == 0 ); } // 2 { - std::system_error err2(s, 95, std::system_category); + std::system_error err2(95, std::system_category, s); VERIFY( err2.code() == std::error_code(95, std::system_category) ); VERIFY( std::strcmp(err2.runtime_error::what(), s.c_str()) == 0 ); } diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc index 09ba2fd13e4e..8e67ce5edae1 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc @@ -26,6 +26,6 @@ int main() { typedef std::system_error test_type; - __gnu_test::diamond_derivation::test(); + __gnu_test::diamond_derivation::test(); return 0; } diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-1.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-1.cc index c178e542a3cc..aef2a95c4ed2 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-1.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-1.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2007 +// Copyright (C) 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -26,29 +26,31 @@ #include #include +using namespace std; + // libstdc++/1972 void test01() { bool test __attribute__((unused)) = true; - std::string s("lack of sunlight, no water error"); + string s("lack of sunlight, no water error"); // 1 - std::system_error obj1 = std::system_error(s); + system_error obj1 = system_error(error_code(), s); // 2 - std::system_error obj2(s); + system_error obj2(error_code(), s); - VERIFY( std::strcmp(obj1.what(), s.data()) == 0 ); - VERIFY( std::strcmp(obj2.what(), s.data()) == 0 ); + VERIFY( strcmp(obj1.what(), s.data()) == 0 ); + VERIFY( strcmp(obj2.what(), s.data()) == 0 ); } void test02() { bool test __attribute__((unused)) = true; - std::string s("lack of sunlight error"); - std::system_error x(s); + string s("lack of sunlight error"); + system_error x(error_code(), s); - VERIFY( std::strcmp(x.what(), s.data()) == 0 ); + VERIFY( strcmp(x.what(), s.data()) == 0 ); } int main(void) diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc index eb8e14c9cc1e..2bb54fb8e265 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2007 +// Copyright (C) 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -30,7 +30,7 @@ class fuzzy_logic : public std::system_error { public: - fuzzy_logic() : std::system_error("whoa") { } + fuzzy_logic() : std::system_error(std::error_code(), "whoa") { } }; void test03() diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc index 23d99a87d947..76d10b8e8281 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc @@ -41,12 +41,12 @@ void test04() const std::string s("CA ISO emergency once again:immediate power down"); const char* strlit1 = "wish I lived in Palo Alto"; const char* strlit2 = "...or Santa Barbara"; - std::system_error obj1(s); + std::system_error obj1(std::error_code(), s); // block 01 { const std::string s2(strlit1); - std::system_error obj2(s2); + std::system_error obj2(std::error_code(), s2); obj1 = obj2; } allocate_on_stack(); @@ -55,7 +55,7 @@ void test04() // block 02 { const std::string s3(strlit2); - std::system_error obj3 = std::system_error(s3); + std::system_error obj3 = std::system_error(std::error_code(), s3); obj1 = obj3; } allocate_on_stack(); diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc index 89570f047211..5934982fa479 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2007 +// Copyright (C) 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -32,7 +32,7 @@ void test01() bool test __attribute__((unused)) = true; std::string s("after nine thirty, this request cannot be met"); - std::system_error obj = std::system_error(s, std::posix_error::invalid_argument); + std::system_error obj = std::system_error(std::posix_error::invalid_argument, s); std::string s1(obj.what()); std::string s2(obj.what()); VERIFY( s1 == s2 ); diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc index 765bcbf19fef..ecf89526b32e 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -30,7 +30,7 @@ void test01() bool test __attribute__((unused)) = true; const std::string xxx(10000, 'x'); - test_type t(xxx); + test_type t(std::error_code(), xxx); VERIFY( std::strcmp(t.what(), xxx.c_str()) == 0 ); } diff --git a/libstdc++-v3/testsuite/util/testsuite_error.h b/libstdc++-v3/testsuite/util/testsuite_error.h new file mode 100644 index 000000000000..56d641874b14 --- /dev/null +++ b/libstdc++-v3/testsuite/util/testsuite_error.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +// Error handling utils for the C++ library testsuite. +// +// Copyright (C) 2007, 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. +// +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include + +#ifndef _TESTSUITE_ERROR_H +#define _TESTSUITE_ERROR_H 1 + +namespace __gnu_test +{ + using std::string; + + struct test_category : public std::error_category + { + virtual const char* + name() const + { + const char* s = "__gnu_test::test_category"; + return s; + } + + virtual string + message(int) const + { return string("message to be determined"); } + + }; + + struct test_derived_category : public test_category + { + virtual const char* + name() const + { + const char* s = "__gnu_test::test_derived_category"; + return s; + } + }; + +} +#endif -- 2.43.5