diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 144ac4792ad..148f2edd1d3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,64 @@ +2007-08-23 Benjamin Kosnik + + * include/std/system_error: New file. + * src/system_error.cc: New file. + * src/Makefile.am (sources): Add. + * src/Makefile.in: Regenerate. + * include/Makefile.am (std_headers): Add system_error. + * include/Makefile.in: Regenerate. + * acinclude.m4 (GLIBCXX_CHECK_SYSTEM_ERROR): New. + * configure.ac: Call it. + * config.h.in: Regenerate. + * include/bits/functional_hash.h: Add hash. + * include/std/ostream: Add inserters for error_code. + + * docs/doxygen/user.cfg.in: Add system_error. + + * config/abi/pre/gnu.ver(GLIBCXX_3.4.10): Add new symbols. + + * testsuite/19_diagnostics/error_code: New. + * testsuite/19_diagnostics/error_code/cons: Same. + * testsuite/19_diagnostics/error_code/cons/1.cc: Same. + * testsuite/19_diagnostics/error_code/operators: Same. + * testsuite/19_diagnostics/error_code/operators/bool.cc: Same. + * testsuite/19_diagnostics/error_code/operators/bool_neg.cc: Same. + * testsuite/19_diagnostics/error_code/operators/equal.cc: Same. + * testsuite/19_diagnostics/error_code/operators/not_equal.cc: Same. + * testsuite/19_diagnostics/error_category: Same. + * testsuite/19_diagnostics/error_category/cons: 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: Same. + * testsuite/19_diagnostics/error_category/operators/equal.cc: Same. + * testsuite/19_diagnostics/error_category/operators/not_equal.cc: Same. + * testsuite/19_diagnostics/headers/system_error: Same. + * testsuite/19_diagnostics/headers/system_error/ + types_std_c++0x.cc: Same. + * testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc: Same. + * testsuite/19_diagnostics/system_error: 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. + * testsuite/27_io/basic_ostream/inserters_other/wchar_t/ + error_code.cc: Same. + * testsuite/27_io/basic_ostream/inserters_other/char/ + error_code.cc: Same. + * testsuite/tr1/6_containers/hash/operators: New. + * testsuite/tr1/6_containers/hash/operators/size_t.cc: Same. + + * testsuite/23_containers/hash: Move... + * testsuite/20_util/hash: ... here. + * testsuite/20_util/hash/operators: New. + * testsuite/20_util/hash/operators/size_t.cc: New. + + * testsuite/20_util/function_objects/bad_function_call: Move... + * testsuite/20_util/bad_function_call: ...here. + 2007-08-21 Benjamin Kosnik * include/Makefile.am (install-data-local): Remove pch-install rules. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 4b3aaa5b58d..012d363f112 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -1257,6 +1257,42 @@ AC_DEFUN([GLIBCXX_CHECK_RANDOM_TR1], [ ]) +dnl +dnl Check whether macros, etc are present for +dnl +AC_DEFUN([GLIBCXX_CHECK_SYSTEM_ERROR], [ + + AC_MSG_CHECKING([for EOWNERDEAD]) + AC_CACHE_VAL(ac_system_error1, [ + AC_TRY_COMPILE([#include ], [ int i = EOWNERDEAD; ], + [ac_system_error1=yes], [ac_system_error1=no]) + ]) + AC_MSG_RESULT($ac_system_error1) + if test x"$ac_system_error1" = x"yes"; then + AC_DEFINE(HAVE_EOWNERDEAD, 1, [Define if EOWNERDEAD exists.]) + fi + + AC_MSG_CHECKING([for ENOTRECOVERABLE]) + AC_CACHE_VAL(ac_system_error2, [ + AC_TRY_COMPILE([#include ], [ int i = ENOTRECOVERABLE; ], + [ac_system_error2=yes], [ac_system_error2=no]) + ]) + AC_MSG_RESULT($ac_system_error2) + if test x"$ac_system_error2" = x"yes"; then + AC_DEFINE(HAVE_ENOTRECOVERABLE, 1, [Define if ENOTRECOVERABLE exists.]) + fi + + AC_MSG_CHECKING([for sys_nerr]) + AC_CACHE_VAL(ac_system_error3, [ + AC_TRY_COMPILE([#include ], [ int i = sys_nerr; ], + [ac_system_error3=yes], [ac_system_error3=no]) + ]) + AC_MSG_RESULT($ac_system_error3) + if test x"$ac_system_error3" = x"yes"; then + AC_DEFINE(HAVE_SYS_NERR, 1, [Define if sys_nerr exists.]) + fi +]) + dnl dnl Check for what type of C headers to use. dnl diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 30a03cc24d3..0efa0915a56 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -63,6 +63,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ENDIAN_H +/* Define if ENOTRECOVERABLE exists. */ +#undef HAVE_ENOTRECOVERABLE + +/* Define if EOWNERDEAD exists. */ +#undef HAVE_EOWNERDEAD + /* Define to 1 if you have the `expf' function. */ #undef HAVE_EXPF @@ -331,6 +337,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MACHINE_H +/* Define if sys_nerr exists. */ +#undef HAVE_SYS_NERR + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PARAM_H diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index a7f378dd236..059d20a19e9 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -447,7 +447,14 @@ GLIBCXX_3.4 { _ZTVNSt6locale5facetE; _ZTVS[a-z]; _ZTVSt[0-9][A-Za-z]*; - _ZTVSt[0-9][0-9][A-Za-z]*; +# _ZTVSt[0-9][0-9][A-Za-z]*; + _ZTVSt[0-9][0-9][A-Z]*; + _ZTVSt[0-9][0-9][a-d]*; + _ZTVSt[0-9][0-9][f-r]*; + _ZTVSt[0-9][0-9][t-z]*; + _ZTVSt[0-9][0-9]e[^r]*; + _ZTVSt[0-9][0-9]s[^y]*; + _ZTVSt11__timepunctI[cw]E; _ZTVSt23__codecvt_abstract_baseI[cw]c11__mbstate_tE; _ZTVSt21__ctype_abstract_baseI[cw]E; @@ -459,14 +466,23 @@ GLIBCXX_3.4 { # typeinfo structure _ZTIS[a-z]; - _ZTINSt8ios_base7failureE; - _ZTINSt6locale5facetE; _ZTISt[0-9][A-Za-z]*; - _ZTISt[0-9][0-9][A-Za-z]*; +# _ZTISt[0-9][0-9][A-Za-z]*; + _ZTISt[0-9][0-9][A-Z]*; + _ZTISt[0-9][0-9][a-d]*; + _ZTISt[0-9][0-9][f-r]*; + _ZTISt[0-9][0-9][t-z]*; + _ZTISt[0-9][0-9]e[^r]*; + _ZTISt[0-9][0-9]s[^y]*; _ZTISt11__timepunctI[cw]E; _ZTISt10__num_base; _ZTISt21__ctype_abstract_baseI[cw]E; _ZTISt23__codecvt_abstract_baseI[cw]c11__mbstate_tE; +# _ZTISt16__numpunct_cacheI[cw]E; +# _ZTISt17__timepunct_cacheI[cw]E; +# _ZTISt18__moneypunct_cacheI[cw]Lb?EE; + _ZTINSt8ios_base7failureE; + _ZTINSt6locale5facetE; _ZTIN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EEE; _ZTIN9__gnu_cxx13stdio_filebufI[cw]St11char_traitsI[cw]EEE; @@ -475,7 +491,14 @@ GLIBCXX_3.4 { _ZTSNSt6locale5facetE; _ZTSS[a-z]; _ZTSSt[0-9][A-Za-z]*; - _ZTSSt[0-9][0-9][A-Za-z]*; +# _ZTSSt[0-9][0-9][A-Za-z]*; + _ZTSSt[0-9][0-9][A-Z]*; + _ZTSSt[0-9][0-9][a-d]*; + _ZTSSt[0-9][0-9][f-r]*; + _ZTSSt[0-9][0-9][t-z]*; + _ZTSSt[0-9][0-9]e[^r]*; + _ZTSSt[0-9][0-9]s[^y]*; + _ZTSSt11__timepunctI[cw]E; _ZTSSt10__num_base; _ZTSSt21__ctype_abstract_baseI[cw]E; @@ -719,6 +742,18 @@ GLIBCXX_3.4.10 { _ZNK11__gnu_debug16_Error_formatter17_M_get_max_lengthEv; + # system_error + _ZSt15system_category; + + _ZTISt14error_category; + _ZTSSt14error_category; + _ZTVSt14error_category; + + _ZTSSt12system_error; + _ZTISt12system_error; + _ZTVSt12system_error; + _ZNSt12system_errorD*Ev; + } GLIBCXX_3.4.9; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 8e78be89292..a41f4f881a8 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -13792,7 +13792,7 @@ _ACEOF -# Check for compiler support that doesn't require linking. +# Enable compiler support that doesn't require linking. echo "$as_me:$LINENO: checking for exception model to use" >&5 echo $ECHO_N "checking for exception model to use... $ECHO_C" >&6 @@ -13956,7 +13956,7 @@ echo "${ECHO_T}$enable_libstdcxx_pch" >&6 -# Enable all the variable C++ runtime options. +# Enable all the variable C++ runtime options that doesn't require linking. echo "$as_me:$LINENO: checking for underlying I/O to use" >&5 echo $ECHO_N "checking for underlying I/O to use... $ECHO_C" >&6 @@ -16530,6 +16530,202 @@ _ACEOF fi +# Checks for operating systems support that don't require linking. + + + echo "$as_me:$LINENO: checking for EOWNERDEAD" >&5 +echo $ECHO_N "checking for EOWNERDEAD... $ECHO_C" >&6 + if test "${ac_system_error1+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + int i = EOWNERDEAD; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_system_error1=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_system_error1=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +fi + + echo "$as_me:$LINENO: result: $ac_system_error1" >&5 +echo "${ECHO_T}$ac_system_error1" >&6 + if test x"$ac_system_error1" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_EOWNERDEAD 1 +_ACEOF + + fi + + echo "$as_me:$LINENO: checking for ENOTRECOVERABLE" >&5 +echo $ECHO_N "checking for ENOTRECOVERABLE... $ECHO_C" >&6 + if test "${ac_system_error2+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + int i = ENOTRECOVERABLE; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_system_error2=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_system_error2=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +fi + + echo "$as_me:$LINENO: result: $ac_system_error2" >&5 +echo "${ECHO_T}$ac_system_error2" >&6 + if test x"$ac_system_error2" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_ENOTRECOVERABLE 1 +_ACEOF + + fi + + echo "$as_me:$LINENO: checking for sys_nerr" >&5 +echo $ECHO_N "checking for sys_nerr... $ECHO_C" >&6 + if test "${ac_system_error3+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ + int i = sys_nerr; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_system_error3=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_system_error3=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +fi + + echo "$as_me:$LINENO: result: $ac_system_error3" >&5 +echo "${ECHO_T}$ac_system_error3" >&6 + if test x"$ac_system_error3" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_SYS_NERR 1 +_ACEOF + + fi + + # No surprises, no surprises... echo "$as_me:$LINENO: checking for thread model used by GCC" >&5 @@ -16571,7 +16767,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu # Fake what AC_TRY_COMPILE does. XXX Look at redoing this new-style. cat > conftest.$ac_ext << EOF -#line 16574 "configure" +#line 16770 "configure" int main() { // NB: _Atomic_word not necessarily int. diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 5d1d947a881..4ad8d0ebfad 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -92,11 +92,11 @@ AC_SUBST(enable_static) ## than just ignoring the results. Faster /and/ more correct, win win. GLIBCXX_ENABLE_HOSTED -# Check for compiler support that doesn't require linking. +# Enable compiler support that doesn't require linking. GLIBCXX_ENABLE_SJLJ_EXCEPTIONS GLIBCXX_ENABLE_PCH($is_hosted) -# Enable all the variable C++ runtime options. +# Enable all the variable C++ runtime options that doesn't require linking. GLIBCXX_ENABLE_CSTDIO GLIBCXX_ENABLE_CLOCALE GLIBCXX_ENABLE_ALLOCATOR @@ -110,6 +110,9 @@ GLIBCXX_ENABLE_DEBUG([no]) GLIBCXX_ENABLE_CXX_FLAGS GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING([no]) +# Checks for operating systems support that don't require linking. +GLIBCXX_CHECK_SYSTEM_ERROR + # No surprises, no surprises... GLIBCXX_ENABLE_THREADS GLIBCXX_ENABLE_ATOMIC_BUILTINS diff --git a/libstdc++-v3/docs/doxygen/user.cfg.in b/libstdc++-v3/docs/doxygen/user.cfg.in index 73fe6777d4d..1484c78f68f 100644 --- a/libstdc++-v3/docs/doxygen/user.cfg.in +++ b/libstdc++-v3/docs/doxygen/user.cfg.in @@ -532,6 +532,7 @@ INPUT = @srcdir@/docs/doxygen/doxygroups.cc \ include/stdexcept \ include/streambuf \ include/string \ + include/system_error \ include/tuple \ include/type_traits \ include/unordered_map \ diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index b7a2a96c2c4..c51128bd9af 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -58,6 +58,7 @@ std_headers = \ ${std_srcdir}/stdexcept \ ${std_srcdir}/streambuf \ ${std_srcdir}/string \ + ${std_srcdir}/system_error \ ${std_srcdir}/tuple \ ${std_srcdir}/type_traits \ ${std_srcdir}/unordered_map \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 876563f5761..f6e69b0e85b 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -303,6 +303,7 @@ std_headers = \ ${std_srcdir}/stdexcept \ ${std_srcdir}/streambuf \ ${std_srcdir}/string \ + ${std_srcdir}/system_error \ ${std_srcdir}/tuple \ ${std_srcdir}/type_traits \ ${std_srcdir}/unordered_map \ diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h index 022c5caf4cc..d5658fe4c50 100644 --- a/libstdc++-v3/include/bits/functional_hash.h +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -59,5 +59,21 @@ # undef _GLIBCXX_INCLUDE_AS_CXX0X #endif +#include + +namespace std +{ + template<> + struct hash : public unary_function + { + size_t + operator()(error_code __e) const + { + const char* __p = reinterpret_cast(&__e); + return _Fnv_hash<>::hash(__p, sizeof(__e)); + } + }; +} + #endif // _FUNCTIONAL_HASH_H diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 2287756513c..67dcc555cff 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -45,6 +45,10 @@ #include #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +# include +#endif + _GLIBCXX_BEGIN_NAMESPACE(std) // [27.6.2.1] Template class basic_ostream @@ -531,6 +535,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return (__out << reinterpret_cast(__s)); } //@} +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + 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()); } +#endif + // [27.6.2.7] standard basic_ostream manipulators /** * @brief Write a newline and flush the stream. diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error new file mode 100644 index 00000000000..3f13622b485 --- /dev/null +++ b/libstdc++-v3/include/std/system_error @@ -0,0 +1,244 @@ +// -*- C++ -*- + +// Copyright (C) 2007 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. + +/** @file include/system_error + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_SYSTEM_ERROR +#define _GLIBCXX_SYSTEM_ERROR 1 + +#pragma GCC system_header + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#endif + +#include +#include +#include +#include + +_GLIBCXX_BEGIN_NAMESPACE(std) + + class system_error; + class error_code; + class error_category; + + extern const error_category& system_category; + + enum posix_errno + { + address_family_not_supported = EAFNOSUPPORT, + address_in_use = EADDRINUSE, + address_not_available = EADDRNOTAVAIL, + already_connected = EISCONN, + argument_list_too_long = E2BIG, + argument_out_of_domain = EDOM, + bad_address = EFAULT, + bad_file_descriptor = EBADF, + bad_message = EBADMSG, + broken_pipe = EPIPE, + connection_aborted = ECONNABORTED, + connection_already_in_progress = EALREADY, + connection_refused = ECONNREFUSED, + connection_reset = ECONNRESET, + cross_device_link = EXDEV, + destination_address_required = EDESTADDRREQ, + device_or_resource_busy = EBUSY, + directory_not_empty = ENOTEMPTY, + executable_format_error = ENOEXEC, + file_exists = EEXIST, + file_too_large = EFBIG, + filename_too_long = ENAMETOOLONG, + function_not_supported = ENOSYS, + host_unreachable = EHOSTUNREACH, + identifier_removed = EIDRM, + illegal_byte_sequence = EILSEQ, + inappropriate_io_control_operation = ENOTTY, + interrupted = EINTR, + invalid_argument = EINVAL, + invalid_seek = ESPIPE, + io_error = EIO, + is_a_directory = EISDIR, + message_size = EMSGSIZE, + network_down = ENETDOWN, + network_reset = ENETRESET, + network_unreachable = ENETUNREACH, + no_buffer_space = ENOBUFS, + no_child_process = ECHILD, + no_link = ENOLINK, + no_lock_available = ENOLCK, + no_message_available = ENODATA, + no_message = ENOMSG, + no_protocol_option = ENOPROTOOPT, + no_space_on_device = ENOSPC, + no_stream_resources = ENOSR, + no_such_device_or_address = ENXIO, + no_such_device = ENODEV, + no_such_file_or_directory = ENOENT, + no_such_process = ESRCH, + not_a_directory = ENOTDIR, + not_a_socket = ENOTSOCK, + not_a_stream = ENOSTR, + not_connected = ENOTCONN, + not_enough_memory = ENOMEM, + not_supported = ENOTSUP, + operation_canceled = ECANCELED, + operation_in_progress = EINPROGRESS, + operation_not_permitted = EPERM, + operation_not_supported = EOPNOTSUPP, + operation_would_block = EWOULDBLOCK, +#ifdef _GLIBCXX_HAVE_EOWNERDEAD + owner_dead = EOWNERDEAD, +#endif + permission_denied = EACCES, + protocol_error = EPROTO, + protocol_not_supported = EPROTONOSUPPORT, + read_only_file_system = EROFS, + resource_deadlock_would_occur = EDEADLK, + resource_unavailable_try_again = EAGAIN, + result_out_of_range = ERANGE, +#ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE + state_not_recoverable = ENOTRECOVERABLE, +#endif + stream_timeout = ETIME, + text_file_busy = ETXTBSY, + timed_out = ETIMEDOUT, + too_many_files_open_in_system = ENFILE, + too_many_files_open = EMFILE, + too_many_links = EMLINK, + too_many_synbolic_link_levels = ELOOP, + value_too_large = EOVERFLOW, + wrong_protocol_type = EPROTOTYPE, + no_posix_equivalent = 1L << 16 + }; + + struct error_category + { + error_category() { } + + bool + operator==(const error_category& __other) const + { return this == &__other; } + + bool + operator!=(const error_category& __other) const + { return this != &__other; } + + virtual posix_errno + posix(int __v) const = 0; + + virtual const string& + name() const = 0; + + private: + error_category(const error_category&); + + error_category& + operator=(const error_category&); + }; + + struct error_code + { + error_code() throw() + : _M_value(0), _M_cat(&system_category) { } + + error_code(int __v, const error_category& __cat) throw() + : _M_value(__v), _M_cat(&__cat) { } + + error_code(posix_errno __v) + : _M_value(__v), _M_cat(&system_category) { } + + void + assign(int __v, const error_category& __cat) throw() + { + _M_value = __v; + _M_cat = &__cat; + } + + void + clear() throw() + { + _M_value = 0; + _M_cat = &system_category; + } + + int + value() const throw() { return _M_value; } + + const error_category& + category() const { return *_M_cat; } + + posix_errno + posix() const throw() { return this->category().posix(_M_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 throw() + { 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; + }; + + class system_error : public std::runtime_error + { + private: + error_code _M_code; + + public: + system_error(const string& __what, error_code __ec = error_code()) + : runtime_error(__what), _M_code(__ec) { } + + system_error(const string& __what, int __v, const error_category& __ecat) + : runtime_error(__what), _M_code(error_code(__v, __ecat)) { } + + virtual ~system_error() throw(); + + const error_code& + code() const throw() { return _M_code; } + }; + +_GLIBCXX_END_NAMESPACE + +#endif + diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index 818735a73ef..cd2aad64b65 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -152,6 +152,7 @@ sources = \ localename.cc \ stdexcept.cc \ strstream.cc \ + system_error.cc \ tree.cc \ allocator-inst.cc \ concept-inst.cc \ @@ -204,6 +205,12 @@ concept-inst.lo: concept-inst.cc concept-inst.o: concept-inst.cc $(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $< +# Use special rules for the C++0x sources so that the proper flags are passed. +system_error.lo: system_error.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +system_error.o: system_error.cc + $(CXXCOMPILE) -std=gnu++0x -c $< + if GLIBCXX_LDBL_COMPAT # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 49ea3b3b273..184b903b6e9 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -72,12 +72,12 @@ am__libstdc___la_SOURCES_DIST = bitmap_allocator.cc pool_allocator.cc \ ctype.cc debug.cc debug_list.cc functexcept.cc globals_io.cc \ ios.cc ios_failure.cc ios_init.cc ios_locale.cc limits.cc \ list.cc locale.cc locale_init.cc locale_facets.cc \ - localename.cc stdexcept.cc strstream.cc tree.cc \ - allocator-inst.cc concept-inst.cc fstream-inst.cc ext-inst.cc \ - ios-inst.cc iostream-inst.cc istream-inst.cc istream.cc \ - locale-inst.cc misc-inst.cc ostream-inst.cc sstream-inst.cc \ - streambuf-inst.cc streambuf.cc string-inst.cc valarray-inst.cc \ - wlocale-inst.cc wstring-inst.cc atomicity.cc \ + localename.cc stdexcept.cc strstream.cc system_error.cc \ + tree.cc allocator-inst.cc concept-inst.cc fstream-inst.cc \ + ext-inst.cc ios-inst.cc iostream-inst.cc istream-inst.cc \ + istream.cc locale-inst.cc misc-inst.cc ostream-inst.cc \ + sstream-inst.cc streambuf-inst.cc streambuf.cc string-inst.cc \ + valarray-inst.cc wlocale-inst.cc wstring-inst.cc atomicity.cc \ codecvt_members.cc collate_members.cc ctype_members.cc \ messages_members.cc monetary_members.cc numeric_members.cc \ time_members.cc basic_file.cc c++locale.cc \ @@ -92,13 +92,13 @@ am__objects_4 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \ debug_list.lo functexcept.lo globals_io.lo ios.lo \ ios_failure.lo ios_init.lo ios_locale.lo limits.lo list.lo \ locale.lo locale_init.lo locale_facets.lo localename.lo \ - stdexcept.lo strstream.lo tree.lo allocator-inst.lo \ - concept-inst.lo fstream-inst.lo ext-inst.lo ios-inst.lo \ - iostream-inst.lo istream-inst.lo istream.lo locale-inst.lo \ - misc-inst.lo ostream-inst.lo sstream-inst.lo streambuf-inst.lo \ - streambuf.lo string-inst.lo valarray-inst.lo wlocale-inst.lo \ - wstring-inst.lo $(am__objects_1) $(am__objects_2) \ - $(am__objects_3) + stdexcept.lo strstream.lo system_error.lo tree.lo \ + allocator-inst.lo concept-inst.lo fstream-inst.lo ext-inst.lo \ + ios-inst.lo iostream-inst.lo istream-inst.lo istream.lo \ + locale-inst.lo misc-inst.lo ostream-inst.lo sstream-inst.lo \ + streambuf-inst.lo streambuf.lo string-inst.lo valarray-inst.lo \ + wlocale-inst.lo wstring-inst.lo $(am__objects_1) \ + $(am__objects_2) $(am__objects_3) am_libstdc___la_OBJECTS = $(am__objects_4) libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) @@ -378,6 +378,7 @@ sources = \ localename.cc \ stdexcept.cc \ strstream.cc \ + system_error.cc \ tree.cc \ allocator-inst.cc \ concept-inst.cc \ @@ -786,6 +787,12 @@ concept-inst.lo: concept-inst.cc concept-inst.o: concept-inst.cc $(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $< +# Use special rules for the C++0x sources so that the proper flags are passed. +system_error.lo: system_error.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +system_error.o: system_error.cc + $(CXXCOMPILE) -std=gnu++0x -c $< + # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. @GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc diff --git a/libstdc++-v3/src/system_error.cc b/libstdc++-v3/src/system_error.cc new file mode 100644 index 00000000000..191625435eb --- /dev/null +++ b/libstdc++-v3/src/system_error.cc @@ -0,0 +1,71 @@ +// implementation file + +// Copyright (C) 2007 +// 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 +#include +#include +#include + +namespace +{ + struct gnu_error_category : public std::error_category + { + virtual const std::string& + name() const + { + static const std::string category("GNU"); + return category; + } + + virtual std::posix_errno + posix(int __v) 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_errno(__v); + else + return std::no_posix_equivalent; + } + }; + + const gnu_error_category gnu_category; +} + +_GLIBCXX_BEGIN_NAMESPACE(std) + + const error_category& system_category = gnu_category; + + system_error::~system_error() throw() { } + +_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 new file mode 100644 index 00000000000..4a3d3ded4aa --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/copy_neg.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::posix_errno(__v); } + + virtual const std::string& + name() const + { + static std::string s("__gnu_test::test_category"); + return s; + } + }; +} + +int main() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::test_category c1; + __gnu_test::test_category c2(c1); + + return 0; +} + +// { dg-error "is private" "" { target *-*-* } 162 } +// { dg-error "within this context" "" { target *-*-* } 29 } +// { dg-error "first required here" "" { target *-*-* } 48 } +// { 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 new file mode 100644 index 00000000000..ae4f5b33bee --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/cons/default.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::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; + } + }; +} + +int main() +{ + bool test __attribute__((unused)) = true; + + // 1 + __gnu_test::test_category c1; + __gnu_test::test_derived_category c2; + + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc new file mode 100644 index 00000000000..4d5b4cd80ba --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/equal.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::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; + } + }; +} + +int main() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::test_category c1; + __gnu_test::test_derived_category c2; + VERIFY( c1 == c1 ); + VERIFY( !(c1 == c2) ); + + return 0; +} 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 new file mode 100644 index 00000000000..7d5f8d3021d --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/not_equal.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::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; + } + }; +} + +int main() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::test_category c1; + __gnu_test::test_derived_category c2; + VERIFY( !(c1 != c1) ); + VERIFY( c1 != c2 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc new file mode 100644 index 00000000000..8732e2891dc --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/1.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::posix_errno(__v); } + + virtual const std::string& + name() const + { + static std::string s("__gnu_test::test_category"); + return s; + } + }; +} + +int main() +{ + bool test __attribute__((unused)) = true; + + // 1 + std::error_code e1; + VERIFY( e1.value() == 0 ); + VERIFY( e1.category() == std::system_category ); + + // 2 + const __gnu_test::test_category cat; + std::error_code e2(e1.value(), cat); + VERIFY( e2.value() == e1.value() ); + VERIFY( e2.category() == cat ); + + // 3 + std::error_code e3(std::operation_not_supported); + VERIFY( e3.value() == int(std::operation_not_supported) ); + VERIFY( e3.category() == std::system_category ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool.cc new file mode 100644 index 00000000000..f4cd48cc6bd --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +// unspecified bool operator positive tests +int main() +{ + bool test __attribute__((unused)) = true; + bool b; + + // 1 + std::error_code e1; + if (e1) + { + VERIFY( false ); + } + + // 2 + std::error_code e2(std::operation_not_supported); + if (e2) + { + VERIFY( true ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool_neg.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool_neg.cc new file mode 100644 index 00000000000..3bf89ba7357 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/bool_neg.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +int main() +{ + std::error_code e; + int i = e; + + return 0; +} + +// { dg-error "invalid conversion" "" { target *-*-* } 29 } diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc new file mode 100644 index 00000000000..e94c52adbb5 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::posix_errno(__v); } + + virtual const std::string& + name() const + { + static std::string s("__gnu_test::test_category"); + return s; + } + }; +} + +// unspecified bool operator positive tests +int main() +{ + bool test __attribute__((unused)) = true; + + std::error_code e1; + std::error_code e2(std::operation_not_supported); + + VERIFY( e1 == e1 ); + VERIFY( !(e1 == e2) ); + + const __gnu_test::test_category cat; + std::error_code e3(e2.value(), cat); + VERIFY( !(e2 == e3) ); + + return 0; +} 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 new file mode 100644 index 00000000000..de487ee98a9 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-22 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +namespace __gnu_test +{ + struct test_category : public std::error_category + { + virtual std::posix_errno + posix(int __v) const + { return std::posix_errno(__v); } + + virtual const std::string& + name() const + { + static std::string s("__gnu_test::test_category"); + return s; + } + }; +} + +// unspecified bool operator positive tests +int main() +{ + bool test __attribute__((unused)) = true; + + std::error_code e1; + std::error_code e2(std::operation_not_supported); + + VERIFY( !(e1 != e1) ); + VERIFY( e1 != e2 ); + + const __gnu_test::test_category cat; + std::error_code e3(e2.value(), cat); + VERIFY( e2 != e3 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/hash/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc similarity index 69% rename from libstdc++-v3/testsuite/23_containers/hash/requirements/explicit_instantiation.cc rename to libstdc++-v3/testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc index 2155ca898bc..fc04cf55fb9 100644 --- a/libstdc++-v3/testsuite/23_containers/hash/requirements/explicit_instantiation.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc @@ -1,4 +1,3 @@ -// { dg-options "-std=gnu++0x" } // { dg-do compile } // Copyright (C) 2007 Free Software Foundation, Inc. @@ -8,17 +7,20 @@ // 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. -#include +// 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. + +#include // { dg-excess-errors "In file included from" } + +// { dg-error "upcoming ISO" "" { target *-*-* } 36 } + + -template class std::hash; diff --git a/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc new file mode 100644 index 00000000000..44d253c1391 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/types_std_c++0x.cc @@ -0,0 +1,119 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007 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. + +#include + +namespace gnu +{ + using std::system_error; + using std::error_code; + using std::error_category; + using std::system_category; + + using std::posix_errno; + using std::address_family_not_supported; + using std::address_in_use; + using std::address_not_available; + using std::already_connected; + using std::argument_list_too_long; + using std::argument_out_of_domain; + using std:: bad_address; + using std::bad_file_descriptor; + using std::bad_message; + using std::broken_pipe; + using std::connection_aborted; + using std::connection_already_in_progress; + using std::connection_refused; + using std::connection_reset; + using std::cross_device_link; + using std::destination_address_required; + using std::device_or_resource_busy; + using std::directory_not_empty; + using std::executable_format_error; + using std::file_exists; + using std::file_too_large; + using std::filename_too_long; + using std::function_not_supported; + using std::host_unreachable; + using std::identifier_removed; + using std::illegal_byte_sequence; + using std::inappropriate_io_control_operation; + using std::interrupted; + using std::invalid_argument; + using std::invalid_seek; + using std::io_error; + using std::is_a_directory; + using std::message_size; + using std::network_down; + using std::network_reset; + using std::network_unreachable; + using std::no_buffer_space; + using std::no_child_process; + using std::no_link; + using std::no_lock_available; + using std::no_message_available; + using std::no_message; + using std::no_posix_equivalent; + using std::no_protocol_option; + using std::no_space_on_device; + using std::no_stream_resources; + using std::no_such_device_or_address; + using std::no_such_device; + using std::no_such_file_or_directory; + using std::no_such_process; + using std::not_a_directory; + using std::not_a_socket; + using std::not_a_stream; + using std::not_connected; + using std::not_enough_memory; + using std::not_supported; + using std::operation_canceled; + using std::operation_in_progress; + using std::operation_not_permitted; + using std::operation_not_supported; + using std::operation_would_block; + +#ifdef _GLIBCXX_HAVE_EOWNERDEAD + using std::owner_dead; +#endif + + using std::permission_denied; + using std::protocol_error; + using std::protocol_not_supported; + using std::read_only_file_system; + using std::resource_deadlock_would_occur; + using std::resource_unavailable_try_again; + using std::result_out_of_range; + +#ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE + using std::state_not_recoverable; +#endif + + using std::stream_timeout; + using std::text_file_busy; + using std::timed_out; + using std::too_many_files_open_in_system; + using std::too_many_files_open; + using std::too_many_links; + using std::too_many_synbolic_link_levels; + using std::value_too_large; + using std::wrong_protocol_type; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc new file mode 100644 index 00000000000..5348e5b15c6 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-05 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + const std::string s("too late: boulangerie out of pain au raisin"); + const std::error_code e(std::operation_not_supported); + + // 1 + { + std::system_error err1(s, e); + 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); + VERIFY( err2.code() == std::error_code(95, std::system_category) ); + VERIFY( std::strcmp(err2.runtime_error::what(), s.c_str()) == 0 ); + } + + return 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 new file mode 100644 index 00000000000..09ba2fd13e4 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons_virtual_derivation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } +// 2007-05-29 Benjamin Kosnik + +// Copyright (C) 2007 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. + +#include +#include + +int main() +{ + typedef std::system_error test_type; + __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 new file mode 100644 index 00000000000..c178e542a3c --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-1.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 +// 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. + +// 19.1 Exception classes + +#include +#include +#include +#include + +// libstdc++/1972 +void test01() +{ + bool test __attribute__((unused)) = true; + std::string s("lack of sunlight, no water error"); + + // 1 + std::system_error obj1 = std::system_error(s); + + // 2 + std::system_error obj2(s); + + VERIFY( std::strcmp(obj1.what(), s.data()) == 0 ); + VERIFY( std::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); + + VERIFY( std::strcmp(x.what(), s.data()) == 0 ); +} + +int main(void) +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc new file mode 100644 index 00000000000..eb8e14c9cc1 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-2.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 +// 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. + +// 19.1 Exception classes + +#include +#include +#include +#include + +// libstdc++/2089 +class fuzzy_logic : public std::system_error +{ +public: + fuzzy_logic() : std::system_error("whoa") { } +}; + +void test03() +{ + bool test __attribute__((unused)) = true; + try + { throw fuzzy_logic(); } + catch(const fuzzy_logic& obj) + { VERIFY( std::strcmp("whoa", obj.what()) == 0 ); } + catch(...) + { VERIFY( false ); } +} + +int main(void) +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc new file mode 100644 index 00000000000..23d99a87d94 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-3.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 +// 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. + +#include +#include +#include +#include + +// test copy ctors, assignment operators, and persistence of member string data +// libstdc++/1972 +// via Greg Bumgardner +void allocate_on_stack(void) +{ + const size_t num = 512; + __extension__ char array[num]; + for (size_t i = 0; i < num; i++) + array[i]=0; +} + +void test04() +{ + bool test __attribute__((unused)) = true; + 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); + + // block 01 + { + const std::string s2(strlit1); + std::system_error obj2(s2); + obj1 = obj2; + } + allocate_on_stack(); + VERIFY( std::strcmp(strlit1, obj1.what()) == 0 ); + + // block 02 + { + const std::string s3(strlit2); + std::system_error obj3 = std::system_error(s3); + obj1 = obj3; + } + allocate_on_stack(); + VERIFY( std::strcmp(strlit2, obj1.what()) == 0 ); +} + +int main(void) +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc new file mode 100644 index 00000000000..e6df84f6007 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-4.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 +// 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. + +// 19.1 Exception classes + +#include +#include +#include +#include + +// Make sure each invocation of what() doesn't grow the message. +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::invalid_argument); + std::string s1(obj.what()); + std::string s2(obj.what()); + VERIFY( s1 == s2 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc new file mode 100644 index 00000000000..765bcbf19fe --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/what-big.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 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. + +#include +#include +#include +#include + +// Can construct and return 10k character error string. +void test01() +{ + typedef std::system_error test_type; + + bool test __attribute__((unused)) = true; + const std::string xxx(10000, 'x'); + test_type t(xxx); + VERIFY( std::strcmp(t.what(), xxx.c_str()) == 0 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/bad_function_call/cons_virtual_derivation.cc b/libstdc++-v3/testsuite/20_util/bad_function_call/cons_virtual_derivation.cc similarity index 100% rename from libstdc++-v3/testsuite/20_util/function_objects/bad_function_call/cons_virtual_derivation.cc rename to libstdc++-v3/testsuite/20_util/bad_function_call/cons_virtual_derivation.cc diff --git a/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc new file mode 100644 index 00000000000..89e82cd4a90 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-20 +// +// Copyright (C) 2007 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. + +#include +#include +#include + +template + void + do_test() + { + bool test __attribute__((unused)) = true; + + typedef T value_type; + typedef std::hash hash_type; + using std::size_t; + + value_type v; // default initialized is fine, same value all that matters. + hash_type h1; + size_t r1 = size_t(h1(v)); + + hash_type h2; + size_t r2 = size_t(h2(v)); + + VERIFY( r1 == r2 ); + } + +void test01() +{ + do_test(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..7b82eeeab2f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007 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. + +#include +#include +#include + +// Verify that we can instantiate hash for every required type. +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; +template class std::hash; + +#ifdef _GLIBCXX_USE_WCHAR_T +template class std::hash; +template class std::hash; +#endif + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc new file mode 100644 index 00000000000..3cac92847e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 Free Software Foundation +// +// 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. + +#include +#include +#include +#include +#include + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + char buf[64]; + error_code e1; + error_code e2(bad_address); + string s, s1, s2; + + { + ostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), ':') != s1.end() ); + + sprintf(buf, "%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + ostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), ':') != s2.end() ); + + sprintf(buf, "%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc new file mode 100644 index 00000000000..a83c9cbb71d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 Free Software Foundation +// +// 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. + +#include +#include +#include +#include +#include +#include + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wchar_t buf[64]; + error_code e1; + error_code e2(bad_address); + wstring s, s1, s2; + + { + wostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), L':') != s1.end() ); + + swprintf(buf, 64, L"%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + wostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), L':') != s2.end() ); + + swprintf(buf, 64, L"%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/hash/operators/size_t.cc b/libstdc++-v3/testsuite/tr1/6_containers/hash/operators/size_t.cc new file mode 100644 index 00000000000..067a9f51da0 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/hash/operators/size_t.cc @@ -0,0 +1,75 @@ +// 2007-08-20 +// +// Copyright (C) 2007 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. + +// 6.3.3 Class template hash + +#include +#include +#include + +template + void + do_test() + { + bool test __attribute__((unused)) = true; + + typedef T value_type; + typedef std::tr1::hash hash_type; + using std::size_t; + + value_type v; // default initialized is fine, same value all that matters. + hash_type h1; + size_t r1 = size_t(h1(v)); + + hash_type h2; + size_t r2 = size_t(h2(v)); + + VERIFY( r1 == r2 ); + } + +void test01() +{ + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + +#ifdef _GLIBCXX_USE_WCHAR_T + do_test(); + do_test(); +#endif +} + +int main() +{ + test01(); + return 0; +}