From 4971b9a8ba2016e1a41927b250e8802eb0787769 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 15 Jul 2008 23:23:23 +0000 Subject: [PATCH] 2008-07-15 Chris Fairles * include/std/chrono: New, as per N2661. * src/chrono.cc: New. * include/Makefile.am: Update. * src/Makefile.am: Likewise. * include/Makefile.in: Regenerate. * src/Makefile.in: Likewise. * acinclude.m4: Add tests for clock_gettime and gettimeofday that define _GLIBCXX_HAS_CLOCK_GETTIME and/or _GLIBCXX_HAS_GETTIMEOFDAY. * configure.ac: Use them. * configure: Regenerate. * config.h.in: Likewise. * config/abi/pre/gnu.ver: Add symbols for system_clock::now() and system_clock::is_monotonic. * testsuite/20_util/duration/cons/1.cc: New. * testsuite/20_util/duration/cons/2.cc: Likewise. * testsuite/20_util/duration/cons/1_neg.cc: Likewise. * testsuite/20_util/duration/requirements/explicit_instantiation/ explicit_instantiation.cc: Likewise. * testsuite/20_util/duration/arithmetic/1.cc: Likewise. * testsuite/20_util/duration/arithmetic/2.cc: Likewise. * testsuite/20_util/duration/comparisons/1.cc: Likewise. * testsuite/20_util/time_point/requirements/explicit_instantiation/ explicit_instantiation.cc: Likewise. * testsuite/20_util/time_point/1.cc: Likewise. * testsuite/20_util/time_point/2.cc: Likewise. * testsuite/20_util/time_point/3.cc: Likewise. * testsuite/20_util/clocks/1.cc: Likewise. * testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add missing headers. * testsuite/17_intro/headers/c++200x/all.cc: Likewise. * include/precompiled/stdc++.h: Likewise and remove . * doc/doxygen/user.cfg.in: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137858 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 35 ++ libstdc++-v3/acinclude.m4 | 88 +++ libstdc++-v3/config.h.in | 9 + libstdc++-v3/config/abi/pre/gnu.ver | 4 + libstdc++-v3/configure | 565 +++++++++++++++++++ libstdc++-v3/configure.ac | 6 + libstdc++-v3/doc/doxygen/user.cfg.in | 3 +- libstdc++-v3/include/Makefile.am | 1 + libstdc++-v3/include/Makefile.in | 1 + libstdc++-v3/include/precompiled/stdc++.h | 3 +- libstdc++-v3/include/std/chrono | 626 +++++++++++++++++++++ libstdc++-v3/src/Makefile.am | 6 + libstdc++-v3/src/Makefile.in | 16 +- libstdc++-v3/src/chrono.cc | 76 +++ .../testsuite/17_intro/headers/c++200x/all.cc | 2 + .../headers/c++200x/all_multiple_inclusion.cc | 5 + libstdc++-v3/testsuite/20_util/clocks/1.cc | 39 ++ .../testsuite/20_util/duration/arithmetic/1.cc | 94 ++++ .../testsuite/20_util/duration/arithmetic/2.cc | 62 ++ .../testsuite/20_util/duration/comparisons/1.cc | 56 ++ libstdc++-v3/testsuite/20_util/duration/cons/1.cc | 138 +++++ .../testsuite/20_util/duration/cons/1_neg.cc | 46 ++ libstdc++-v3/testsuite/20_util/duration/cons/2.cc | 120 ++++ .../explicit_instantiation.cc | 27 + libstdc++-v3/testsuite/20_util/time_point/1.cc | 49 ++ libstdc++-v3/testsuite/20_util/time_point/2.cc | 72 +++ libstdc++-v3/testsuite/20_util/time_point/3.cc | 53 ++ .../explicit_instantiation.cc | 25 + 28 files changed, 2220 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/include/std/chrono create mode 100644 libstdc++-v3/src/chrono.cc create mode 100644 libstdc++-v3/testsuite/20_util/clocks/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/comparisons/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/cons/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/cons/2.cc create mode 100644 libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/20_util/time_point/1.cc create mode 100644 libstdc++-v3/testsuite/20_util/time_point/2.cc create mode 100644 libstdc++-v3/testsuite/20_util/time_point/3.cc create mode 100644 libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e78c7d67f64..3301a014ccf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,38 @@ +2008-07-15 Chris Fairles + + * include/std/chrono: New, as per N2661. + * src/chrono.cc: New. + * include/Makefile.am: Update. + * src/Makefile.am: Likewise. + * include/Makefile.in: Regenerate. + * src/Makefile.in: Likewise. + * acinclude.m4: Add tests for clock_gettime and gettimeofday that + define _GLIBCXX_HAS_CLOCK_GETTIME and/or _GLIBCXX_HAS_GETTIMEOFDAY. + * configure.ac: Use them. + * configure: Regenerate. + * config.h.in: Likewise. + * config/abi/pre/gnu.ver: Add symbols for system_clock::now() and + system_clock::is_monotonic. + * testsuite/20_util/duration/cons/1.cc: New. + * testsuite/20_util/duration/cons/2.cc: Likewise. + * testsuite/20_util/duration/cons/1_neg.cc: Likewise. + * testsuite/20_util/duration/requirements/explicit_instantiation/ + explicit_instantiation.cc: Likewise. + * testsuite/20_util/duration/arithmetic/1.cc: Likewise. + * testsuite/20_util/duration/arithmetic/2.cc: Likewise. + * testsuite/20_util/duration/comparisons/1.cc: Likewise. + * testsuite/20_util/time_point/requirements/explicit_instantiation/ + explicit_instantiation.cc: Likewise. + * testsuite/20_util/time_point/1.cc: Likewise. + * testsuite/20_util/time_point/2.cc: Likewise. + * testsuite/20_util/time_point/3.cc: Likewise. + * testsuite/20_util/clocks/1.cc: Likewise. + * testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add + missing headers. + * testsuite/17_intro/headers/c++200x/all.cc: Likewise. + * include/precompiled/stdc++.h: Likewise and remove . + * doc/doxygen/user.cfg.in: Likewise. + 2008-07-15 Paolo Carlini PR libstdc++/36832 diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index a68ab9be2a8..e998471c446 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -1009,6 +1009,94 @@ AC_DEFUN([GLIBCXX_ENABLE_C99], [ dnl +dnl Check for IEEE Std 1003.1-2001 clock_gettime required for +dnl 20.8.5 [time.clock] in the current C++0X working draft. +dnl +AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no) + + ac_has_clock_monotonic=no; + ac_has_clock_realtime=no; + if test x"$ac_has_unistd_h" = x"yes"; then + AC_MSG_CHECKING([for monotonic clock]) + AC_TRY_LINK( + [#include + #include + ], + [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) + timespec tp; + #endif + clock_gettime(CLOCK_MONOTONIC, &tp); + ], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no]) + + AC_MSG_RESULT($ac_has_clock_monotonic) + + AC_MSG_CHECKING([for realtime clock]) + AC_TRY_LINK( + [#include + #include + ], + [#if _POSIX_TIMERS > 0 + timespec tp; + #endif + clock_gettime(CLOCK_REALTIME, &tp); + ], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no]) + + AC_MSG_RESULT($ac_has_clock_realtime) + fi + + if test x"$ac_has_clock_monotonic" = x"yes"; then + AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1, + [ Defined if clock_gettime has monotonic clock support. ]) + fi + + if test x"$ac_has_clock_realtime" = x"yes"; then + AC_DEFINE(_GLIBCXX_USE_CLOCK_REALTIME, 1, + [ Defined if clock_gettime has realtime clock support. ]) + fi + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + +dnl +dnl Check for IEEE Std 1003.1-2001 gettimeofday required for +dnl 20.8.5 [time.clock] in the current C++0X working draft. +dnl +AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + ac_has_gettimeofday=no; + AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no) + if test x"$ac_has_sys_time_h" = x"yes"; then + AC_MSG_CHECKING([for gettimeofday]) + AC_TRY_LINK([#include ], + [timeval tv; gettimeofday(&tv, 0);], + [ac_has_gettimeofday=yes], [ac_has_gettimeofday=no]) + + AC_MSG_RESULT($ac_has_gettimeofday) + fi + + if test x"$ac_has_gettimeofday" = x"yes"; then + AC_DEFINE(_GLIBCXX_USE_GETTIMEOFDAY, 1, + [ Defined if gettimeofday is available. ]) + fi + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + +dnl dnl Check for ISO/IEC 9899:1999 "C99" support to ISO/IEC DTR 19768 "TR1" dnl facilities in Chapter 8, "C compatibility". dnl diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index d107f481be7..256637abcec 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -811,6 +811,15 @@ namespace std::tr1. */ #undef _GLIBCXX_USE_C99_STDINT_TR1 +/* Defined if clock_gettime has monotonic clock support. */ +#undef _GLIBCXX_USE_CLOCK_MONOTONIC + +/* Defined if clock_gettime has realtime clock support. */ +#undef _GLIBCXX_USE_CLOCK_REALTIME + +/* Defined if gettimeofday is available. */ +#undef _GLIBCXX_USE_GETTIMEOFDAY + /* Define if LFS support is available. */ #undef _GLIBCXX_USE_LFS diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 8327d10511f..a9c94fc694b 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -885,6 +885,10 @@ GLIBCXX_3.4.11 { # char16_t and char32_t _ZNSt14numeric_limitsIu8char*; + # chrono + _ZNSt6chrono12system_clock12is_monotonicE; + _ZNSt6chrono12system_clock3nowEv; + } GLIBCXX_3.4.10; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 5a960cd2561..901a2dc1e4f 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -40947,6 +40947,571 @@ _ACEOF + # For clock_gettime support. + + + + + ac_ext=cc +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + +for ac_header in unistd.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_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_cxx_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_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 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); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_cxx_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ----------------------------------------- ## +## Report this to the package-unused lists. ## +## ----------------------------------------- ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + ac_has_unistd_h=yes +else + ac_has_unistd_h=no +fi + +done + + + ac_has_clock_monotonic=no; + ac_has_clock_realtime=no; + if test x"$ac_has_unistd_h" = x"yes"; then + echo "$as_me:$LINENO: checking for monotonic clock" >&5 +echo $ECHO_N "checking for monotonic clock... $ECHO_C" >&6 + if test x$gcc_no_link = xyes; then + { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5 +echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;} + { (exit 1); exit 1; }; } +fi +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + #include + +int +main () +{ +#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) + timespec tp; + #endif + clock_gettime(CLOCK_MONOTONIC, &tp); + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 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_cxx_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_exeext' + { (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_has_clock_monotonic=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_has_clock_monotonic=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + echo "$as_me:$LINENO: result: $ac_has_clock_monotonic" >&5 +echo "${ECHO_T}$ac_has_clock_monotonic" >&6 + + echo "$as_me:$LINENO: checking for realtime clock" >&5 +echo $ECHO_N "checking for realtime clock... $ECHO_C" >&6 + if test x$gcc_no_link = xyes; then + { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5 +echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;} + { (exit 1); exit 1; }; } +fi +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + #include + +int +main () +{ +#if _POSIX_TIMERS > 0 + timespec tp; + #endif + clock_gettime(CLOCK_REALTIME, &tp); + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 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_cxx_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_exeext' + { (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_has_clock_realtime=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_has_clock_realtime=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + echo "$as_me:$LINENO: result: $ac_has_clock_realtime" >&5 +echo "${ECHO_T}$ac_has_clock_realtime" >&6 + fi + + if test x"$ac_has_clock_monotonic" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define _GLIBCXX_USE_CLOCK_MONOTONIC 1 +_ACEOF + + fi + + if test x"$ac_has_clock_realtime" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define _GLIBCXX_USE_CLOCK_REALTIME 1 +_ACEOF + + fi + + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + # For gettimeofday support. + + + + + ac_ext=cc +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + ac_has_gettimeofday=no; + +for ac_header in sys/time.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_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_cxx_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_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 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); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_cxx_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ----------------------------------------- ## +## Report this to the package-unused lists. ## +## ----------------------------------------- ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + ac_has_sys_time_h=yes +else + ac_has_sys_time_h=no +fi + +done + + if test x"$ac_has_sys_time_h" = x"yes"; then + echo "$as_me:$LINENO: checking for gettimeofday" >&5 +echo $ECHO_N "checking for gettimeofday... $ECHO_C" >&6 + if test x$gcc_no_link = xyes; then + { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5 +echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;} + { (exit 1); exit 1; }; } +fi +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 () +{ +timeval tv; gettimeofday(&tv, 0); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 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_cxx_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_exeext' + { (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_has_gettimeofday=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_has_gettimeofday=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + echo "$as_me:$LINENO: result: $ac_has_gettimeofday" >&5 +echo "${ECHO_T}$ac_has_gettimeofday" >&6 + fi + + if test x"$ac_has_gettimeofday" = x"yes"; then + +cat >>confdefs.h <<\_ACEOF +#define _GLIBCXX_USE_GETTIMEOFDAY 1 +_ACEOF + + fi + + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # For TLS support. # Check whether --enable-tls or --disable-tls was given. diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 19501aac1be..b23e17714dd 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -161,6 +161,12 @@ if $GLIBCXX_IS_NATIVE; then # For dev/random and dev/urandom for TR1. GLIBCXX_CHECK_RANDOM_TR1 + # For clock_gettime support. + GLIBCXX_CHECK_CLOCK_GETTIME + + # For gettimeofday support. + GLIBCXX_CHECK_GETTIMEOFDAY + # For TLS support. GCC_CHECK_TLS diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in index 3c59dcbb831..849d64e2415 100644 --- a/libstdc++-v3/doc/doxygen/user.cfg.in +++ b/libstdc++-v3/doc/doxygen/user.cfg.in @@ -468,8 +468,8 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \ include/algorithm \ include/array \ include/bitset \ + include/chrono \ include/condition_variable \ - include/date_time \ include/deque \ include/fstream \ include/functional \ @@ -489,6 +489,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \ include/ostream \ include/queue \ include/random \ + include/ratio \ include/regex \ include/set \ include/sstream \ diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 5d8358b42eb..1249930c80d 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -32,6 +32,7 @@ std_headers = \ ${std_srcdir}/array \ ${std_srcdir}/bitset \ ${std_srcdir}/c++0x_warning.h \ + ${std_srcdir}/chrono \ ${std_srcdir}/complex \ ${std_srcdir}/condition_variable \ ${std_srcdir}/deque \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 5820f2612a4..cb529671e3a 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -285,6 +285,7 @@ std_headers = \ ${std_srcdir}/array \ ${std_srcdir}/bitset \ ${std_srcdir}/c++0x_warning.h \ + ${std_srcdir}/chrono \ ${std_srcdir}/complex \ ${std_srcdir}/condition_variable \ ${std_srcdir}/deque \ diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index e4b61106734..b9249353678 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -98,8 +98,9 @@ #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include -#include +#include #include +#include #include #include #include diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono new file mode 100644 index 00000000000..74fee965f9a --- /dev/null +++ b/libstdc++-v3/include/std/chrono @@ -0,0 +1,626 @@ +// -*- C++ -*- + +// Copyright (C) 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. + +/** @file include/chrono + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_CHRONO +#define _GLIBCXX_CHRONO 1 + +#pragma GCC system_header + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#else + +#ifdef _GLIBCXX_INCLUDE_AS_TR1 +# error C++0x header cannot be included from TR1 header +#endif + +#include +#include +#include +#include + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + +namespace std +{ + namespace chrono + { + template> + struct duration; + + template + struct time_point; + } + + // 20.8.2.3 specialization of common_type (for duration) + template + struct common_type, + chrono::duration<_Rep2, _Period2>> + { + typedef chrono::duration::type, + ratio<__static_gcd<_Period1::num, _Period2::num>::value, + (_Period1::den / __static_gcd<_Period1::den, _Period2::den>::value) + * _Period2::den>> type; + }; + + // 20.8.2.3 specialization of common_type (for time_point) + template + struct common_type, + chrono::time_point<_Clock, _Duration2>> + { + typedef chrono::time_point<_Clock, + typename common_type<_Duration1, _Duration2>::type> type; + }; + + namespace chrono + { + // primary template for duration_cast impl. + template + struct __duration_cast_impl + { + template + static _ToDuration __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast< + typename _ToDuration::rep>(static_cast<_CR>(__d.count()) + * static_cast<_CR>(_CF::num) + / static_cast<_CR>(_CF::den))); + } + }; + + template + struct __duration_cast_impl<_ToDuration, _CF, _CR, true, true> + { + template + static _ToDuration __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration( + static_cast(__d.count())); + } + }; + + template + struct __duration_cast_impl<_ToDuration, _CF, _CR, true, false> + { + template + static _ToDuration __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast( + static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); + } + }; + + template + struct __duration_cast_impl<_ToDuration, _CF, _CR, false, true> + { + template + static _ToDuration __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast( + static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); + } + }; + + template + inline _ToDuration + duration_cast(const duration<_Rep, _Period>& __d) + { + typedef typename + ratio_divide<_Period, typename _ToDuration::period>::type __cf; + typedef typename + common_type::type __cr; + + return __duration_cast_impl<_ToDuration, __cf, __cr, + __cf::num == 1, __cf::den == 1>::__cast(__d); + } + + template + struct treat_as_floating_point + : is_floating_point<_Rep> + { }; + + template + struct duration_values + { + static const _Rep + zero() + { return _Rep(0); } + + static const _Rep + max() + { return numeric_limits<_Rep>::max(); } + + static const _Rep + min() + { return numeric_limits<_Rep>::min(); } + }; + + template + struct duration + { + static_assert(_Period::num > 0, "period must be positive"); + + typedef _Rep rep; + typedef _Period period; + + // construction / destruction + duration () + : __r(rep(0)) + { } + + template + explicit duration(_Rep2 const& __rep) + : __r(static_cast(__rep)) + { + static_assert(is_convertible<_Rep2,rep>::value == true + && (treat_as_floating_point::value == true + || (!treat_as_floating_point::value + && !treat_as_floating_point<_Rep2>::value)), + "cannot construct integral duration with floating point type"); + } + + duration(const duration& __d) + : __r(__d.count()) + { } + + // conversions + template + duration(const duration<_Rep2, _Period2>& __d) + : __r(duration_cast(__d).count()) + { + static_assert(treat_as_floating_point::value == true + || ratio_divide<_Period2, period>::type::den == 1, + "the resulting duration is not exactly representable"); + } + + // observer + rep + count() const + { return __r; } + + // arithmetic + duration + operator+() const + { return *this; } + + duration + operator-() const + { return duration(-__r); } + + duration& + operator++() + { + ++__r; + return *this; + } + + duration + operator++(int) + { return duration(__r++); } + + duration& + operator--() + { + --__r; + return *this; + } + + duration + operator--(int) + { return duration(__r--); } + + duration& + operator+=(const duration& __d) + { + __r += __d.count(); + return *this; + } + + duration& + operator-=(const duration& __d) + { + __r -= __d.count(); + return *this; + } + + duration& + operator*=(const rep& __rhs) + { + __r *= __rhs; + return *this; + } + + duration& + operator/=(const rep& __rhs) + { + __r /= __rhs; + return *this; + } + + // special values + // TODO: These should be constexprs. + static const duration + zero() + { return duration(duration_values::zero()); } + + static const duration + min() + { return duration(duration_values::min()); } + + static const duration + max() + { return duration(duration_values::max()); } + + private: + rep __r; + }; + + template + inline typename common_type, + duration<_Rep2, _Period2>>::type + operator+(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { + typedef typename common_type, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs) += __rhs; + } + + template + inline typename common_type, + duration<_Rep2, _Period2>>::type + operator-(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { + typedef typename common_type, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs) -= __rhs; + } + + template + inline duration::type, _Period> + operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) + { + typedef typename common_type<_Rep1, _Rep2>::type __cr; + return duration<__cr, _Period>(__d) *= __s; + } + + template + inline duration::type, _Period> + operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d) + { return __d * __s; } + + template + struct __is_not_duration + : std::true_type + { }; + + template + struct __is_not_duration> + : std::false_type + { }; + + template + struct __division_impl; + + template + struct __division_impl, _Rep2, + typename enable_if<__is_not_duration<_Rep2>::value>::type> + { + typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef + duration::type, _Period> __rt; + + static __rt + __divide(const duration<_Rep1, _Period>& __d, const _Rep2& __s) + { return duration<__cr, _Period>(__d) /= __s; } + }; + + template + struct __division_impl, + duration<_Rep2, _Period2>> + { + typedef typename common_type, + duration<_Rep2, _Period2>>::type __ct; + typedef typename common_type<_Rep1, _Rep2>::type __rt; + + static __rt + __divide(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return __ct(__lhs).count() / __ct(__rhs).count(); } + }; + + template + inline typename __division_impl, _Up>::__rt + operator/(const duration<_Rep, _Period>& __d, const _Up& __u) + { + return + __division_impl, _Up>::__divide(__d, __u); + } + + // comparisons + template + inline bool + operator==(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { + typedef typename common_type, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs).count() == __ct(__rhs).count(); + } + + template + inline bool + operator<(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { + typedef typename common_type, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs).count() < __ct(__rhs).count(); + } + + template + inline bool + operator!=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return !(__lhs == __rhs); } + + template + inline bool + operator<=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return !(__rhs < __lhs); } + + template + inline bool + operator>(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return __rhs < __lhs; } + + template + inline bool + operator>=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return !(__lhs < __rhs); } + + typedef duration nanoseconds; + typedef duration microseconds; + typedef duration milliseconds; + typedef duration seconds; + typedef duration> minutes; + typedef duration> hours; + + template + struct time_point + { + typedef _Clock clock; + typedef _Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; + + time_point() + : __d(duration::zero()) + { } + + explicit time_point(const duration& __dur) + : __d(duration::zero() + __dur) + { } + + // conversions + template + time_point(const time_point& __t) + : __d(__t.time_since_epoch()) + { } + + // observer + duration + time_since_epoch() const + { return __d; } + + // arithmetic + time_point& + operator+=(const duration& __dur) + { + __d += __dur; + return *this; + } + + time_point& + operator-=(const duration& __dur) + { + __d -= __dur; + return *this; + } + + // special values + // TODO: These should be constexprs. + static const time_point + min() + { return time_point(duration::min()); } + + static const time_point + max() + { return time_point(duration::max()); } + + private: + duration __d; + }; + + template + inline time_point<_Clock, _ToDuration> + time_point_cast(const time_point<_Clock, _Duration>& __t) + { + return time_point<_Clock, _ToDuration>( + duration_cast<_ToDuration>(__t.time_since_epoch())); + } + + template + inline time_point<_Clock, + typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator+(const time_point<_Clock, _Duration1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { + typedef time_point<_Clock, + typename common_type<_Duration1, + duration<_Rep2, _Period2>>::type> __ct; + return __ct(__lhs) += __rhs; + } + + template + inline time_point<_Clock, + typename common_type, _Duration2>::type> + operator+(const duration<_Rep1, _Period1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return __rhs + __lhs; } + + template + inline time_point<_Clock, + typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator-(const time_point<_Clock, _Duration1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) + { return __lhs + (-__rhs); } + + template + inline typename common_type<_Duration1, _Duration2>::type + operator-(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } + + template + inline bool + operator==(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } + + template + inline bool + operator!=(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return !(__lhs == __rhs); } + + template + inline bool + operator<(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } + + template + inline bool + operator<=(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return !(__rhs < __lhs); } + + template + inline bool + operator>(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return __rhs < __lhs; } + + template + inline bool + operator>=(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) + { return !(__lhs < __rhs); } + + struct system_clock + { +#if defined(_GLIBCXX_USE_CLOCK_MONOTONIC) || \ + defined(_GLIBCXX_USE_CLOCK_REALTIME) + typedef chrono::nanoseconds duration; +#elif defined(_GLIBCXX_USE_GETTIMEOFDAY) + typedef chrono::microseconds duration; +#else + typedef chrono::seconds duration; +#endif + + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + +#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC + static const bool is_monotonic = true; +#else + static const bool is_monotonic = false; +#endif + + static time_point + now(); + + // Map to C API + static std::time_t + to_time_t(const time_point& __t) + { + return std::time_t( + duration_cast(__t.time_since_epoch()).count()); + } + + static time_point + from_time_t(std::time_t __t) + { + return time_point_cast( + chrono::time_point( + chrono::seconds(__t))); + } + + // TODO: requires constexpr + /* + static_assert( + system_clock::duration::min() < + system_clock::duration::zero(), + "a clock's minimum duration cannot be less than its epoch"); + */ + }; + + typedef system_clock high_resolution_clock; + typedef system_clock monotonic_clock; + } +} + +#endif //_GLIBCXX_USE_C99_STDINT_TR1 + +#endif //__GXX_EXPERIMENTAL_CXX0X__ + +#endif //_GLIBCXX_CHRONO diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index 8d2cbf5e14b..d41f3ebf290 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -186,6 +186,7 @@ sources = \ wstring-inst.cc \ mutex.cc \ condition_variable.cc \ + chrono.cc \ ${host_sources} \ ${host_sources_extra} @@ -272,6 +273,11 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< +chrono.lo: chrono.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +chrono.o: chrono.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 f0e98973d3f..27c9b70c0be 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -84,10 +84,10 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.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 mutex.cc condition_variable.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 \ + wstring-inst.cc mutex.cc condition_variable.cc chrono.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 \ compatibility-ldbl.cc parallel_list.cc parallel_settings.cc am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \ ctype_members.lo messages_members.lo monetary_members.lo \ @@ -109,7 +109,7 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.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 mutex.lo condition_variable.lo \ + wstring-inst.lo mutex.lo condition_variable.lo chrono.lo \ $(am__objects_1) $(am__objects_4) am_libstdc___la_OBJECTS = $(am__objects_5) libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS) @@ -422,6 +422,7 @@ sources = \ wstring-inst.cc \ mutex.cc \ condition_variable.cc \ + chrono.cc \ ${host_sources} \ ${host_sources_extra} @@ -866,6 +867,11 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< +chrono.lo: chrono.cc + $(LTCXXCOMPILE) -std=gnu++0x -c $< +chrono.o: chrono.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/chrono.cc b/libstdc++-v3/src/chrono.cc new file mode 100644 index 00000000000..88fb4c180e9 --- /dev/null +++ b/libstdc++-v3/src/chrono.cc @@ -0,0 +1,76 @@ +// chrono -*- C++ -*- + +// Copyright (C) 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 + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + +// conditional inclusion of sys/time.h for gettimeofday +#if !defined(_GLIBCXX_USE_CLOCK_MONOTONIC) && \ + !defined(_GLIBCXX_USE_CLOCK_REALTIME) && \ + defined(_GLIBCXX_USE_GETTIMEOFDAY) +#include +#endif + +namespace std +{ + namespace chrono + { + const bool system_clock::is_monotonic; + + system_clock::time_point + system_clock::now() + { +#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC + timespec tp; + // -EINVAL, -EFAULT + clock_gettime(CLOCK_MONOTONIC, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +#elif defined(_GLIBCXX_USE_CLOCK_REALTIME) + timespec tp; + // -EINVAL, -EFAULT + clock_gettime(CLOCK_REALTIME, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +#elif defined(_GLIBCXX_USE_GETTIMEOFDAY) + timeval tv; + // EINVAL, EFAULT + gettimeofday(&tv, NULL); + return time_point(duration(chrono::seconds(tv.tv_sec) + + chrono::microseconds(tv.tv_usec))); +#else + std::time_t __sec = std::time(0); + return system_clock::from_time_t(__sec); +#endif + } + } +} + +#endif // _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc index 7988666739a..4c2e31be081 100644 --- a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc +++ b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -118,6 +119,7 @@ #include #include #include +#include #include #include #include diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc index 814fbc3a144..f88edc8268a 100644 --- a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc +++ b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc @@ -93,6 +93,7 @@ #include #include #include +#include #include #include #include @@ -114,6 +115,7 @@ #include #include #include +#include #include #include #include @@ -203,6 +205,7 @@ #include #include #include +#include #include #include #include @@ -219,11 +222,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include diff --git a/libstdc++-v3/testsuite/20_util/clocks/1.cc b/libstdc++-v3/testsuite/20_util/clocks/1.cc new file mode 100644 index 00000000000..bcbe210d22f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/clocks/1.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.5 Clocks [time.clock] + +#include + +// 20.8.5.1 system_clock [time.clock.system] +int +main() +{ + using namespace std::chrono; + + system_clock::time_point t1 = system_clock::now(); + bool is_monotonic = system_clock::is_monotonic; + is_monotonic = is_monotonic; // suppress unused warning + std::time_t t2 = system_clock::to_time_t(t1); + system_clock::time_point t3 = system_clock::from_time_t(t2); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc new file mode 100644 index 00000000000..55533eb1dde --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3 Class template duration [time.duration] + +#include +#include + +// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (unary member ops) +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration d0(3); + duration d1 = -d0; + VERIFY(d0.count() == 3); + VERIFY(d1.count() == -3); + + duration d2 = (+d0); + VERIFY(d2.count() == 3); + + duration d3(++d2); + VERIFY(d2.count() == 4); + VERIFY(d3.count() == 4); + + duration d4(d3++); + VERIFY(d3.count() == 5); + VERIFY(d4.count() == 4); + + duration d5(--d4); + VERIFY(d4.count() == 3); + VERIFY(d5.count() == 3); + + duration d6(d5--); + VERIFY(d5.count() == 2); + VERIFY(d6.count() == 3); +} + +// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (binary member ops) +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration d7(3); + duration d8(9); + d7 += d8; + VERIFY(d7.count() == 12); + VERIFY(d8.count() == 9); + + duration d9(3); + duration d10(9); + d9 -= d10; + VERIFY(d9.count() == -6); + VERIFY(d10.count() == 9); + + duration d11(9); + int i = 3; + d11 *= i; + VERIFY(d11.count() == 27); + + duration d12(12); + d12 /= i; + VERIFY(d12.count() == 4); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc new file mode 100644 index 00000000000..e096334c980 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3 Class template duration [time.duration] + +#include +#include + +// 20.8.3.5 duration non-member arithmetic [time.duration.nonmember] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration d0(12); + duration d1(3); + int i = 3; + + duration d2 = d0 + d1; + VERIFY(d2.count() == 15); + + duration d3 = d0 - d1; + VERIFY(d3.count() == 9); + + duration d4 = d0 * i; + VERIFY(d4.count() == 36); + + duration d5 = i * d0; + VERIFY(d5.count() == 36); + + duration d6 = d0 / i; + VERIFY(d6.count() == 4); + + int j = d0 / d1; + VERIFY(j == 4); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/comparisons/1.cc b/libstdc++-v3/testsuite/20_util/duration/comparisons/1.cc new file mode 100644 index 00000000000..31ac42ddcee --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/comparisons/1.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3 Class template duration [time.duration] + +#include +#include + +// 20.8.3.6 duration comparisons [time.duration.comparisons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration d0(12); + duration d1(3); + duration d2(3); + + VERIFY(d1 < d0); + VERIFY(d0 > d1); + + VERIFY(d0 != d1); + VERIFY(d1 == d2); + + VERIFY(d1 <= d2); + VERIFY(d1 >= d2); + + VERIFY(d1 <= d0); + VERIFY(d0 >= d1); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/1.cc b/libstdc++-v3/testsuite/20_util/duration/cons/1.cc new file mode 100644 index 00000000000..6d12dbb5bd7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/1.cc @@ -0,0 +1,138 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3 Class template duration [time.duration] + +#include +#include +#include + +template +struct type_emulator +{ + type_emulator() + : i(T(0)) { } + + type_emulator(T j) + : i(j) { } + + type_emulator(const type_emulator& e) + : i(e.i) { } + + type_emulator& + operator*=(type_emulator a) + { + i *= a.i; + return *this; + } + + type_emulator& + operator+=(type_emulator a) + { + i += a.i; + return *this; + } + + operator T () + { return i; } + + T i; +}; + +template +bool +operator==(type_emulator a, type_emulator b) +{ return a.i == b.i; } + +template +bool +operator<(type_emulator a, type_emulator b) +{ return a.i < b.i; } + +template +type_emulator +operator+(type_emulator a, type_emulator b) +{ return a += b; } + +template +type_emulator +operator*(type_emulator a, type_emulator b) +{ return a *= b; } + +namespace std +{ + template + struct common_type, U> + { typedef typename common_type::type type; }; + + template + struct common_type> + { typedef typename common_type::type type; }; + + template + struct common_type, type_emulator> + { typedef typename common_type::type type; }; + + namespace chrono + { + template + struct treat_as_floating_point> + : is_floating_point + { }; + } +} + +typedef type_emulator int_emulator; +typedef type_emulator dbl_emulator; + +// 20.8.3.1 duration constructors [time.duration.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using std::chrono::duration; + + duration d0; + VERIFY(d0.count() == static_cast::rep>(0)); + + int r = 3; + duration d1(r); + VERIFY(d1.count() == static_cast::rep>(r)); + + double s = 8.0; + duration d2(s); + VERIFY(d2.count() == static_cast::rep>(s)); + + int_emulator ie(3); + duration d3(ie); + VERIFY(d3.count() == static_cast::rep>(ie)); + + dbl_emulator de(4.0); + duration d4(de); + VERIFY(d4.count() == static_cast::rep>(de)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc new file mode 100644 index 00000000000..8710d74de7e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3.1 duration constructors [time.duration.cons] + +#include + +void +test01() +{ + std::chrono::duration d1(1.0); +} + +void +test02() +{ + using namespace std::chrono; + + duration d2(8); + duration d2_copy(d2); +} + +// { dg-error "instantiated from here" "" { target *-*-* } 30 } +// { dg-error "instantiated from here" "" { target *-*-* } 39 } +// { dg-error "not exactly representable" "" { target *-*-* } 202 } +// { dg-error "integral duration with floating point" "" { target *-*-* } 186 } +// { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/2.cc b/libstdc++-v3/testsuite/20_util/duration/cons/2.cc new file mode 100644 index 00000000000..b491224dc48 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/2.cc @@ -0,0 +1,120 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.3 Class template duration [time.duration] + +#include +#include +#include + +template +struct type_emulator +{ + type_emulator() : i(T(0)) { } + type_emulator(T j) : i(j) { } + type_emulator(const type_emulator& e) : i(e.i) { } + + type_emulator& operator*=(type_emulator a) + { i *= a.i; return *this; } + + type_emulator& operator+=(type_emulator a) + { i += a.i; return *this; } + + operator T () { return i; } + T i; +}; + +template +bool operator==(type_emulator a, type_emulator b) +{ return a.i == b.i; } + +template +bool operator<(type_emulator a, type_emulator b) +{ return a.i < b.i; } + +template +type_emulator operator+(type_emulator a, type_emulator b) +{ return a += b; } + +template +type_emulator operator*(type_emulator a, type_emulator b) +{ return a *= b; } + +namespace std +{ + template + struct common_type, U> + { typedef typename common_type::type type; }; + + template + struct common_type> + { typedef typename common_type::type type; }; + + template + struct common_type, type_emulator> + { typedef typename common_type::type type; }; + + namespace chrono + { + template + struct treat_as_floating_point> + : is_floating_point + { }; + } +} + +typedef type_emulator int_emulator; +typedef type_emulator dbl_emulator; + +// 20.8.3.1 duration constructors [time.duration.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration d0(3); + duration d0_copy(d0); + VERIFY(d0_copy.count() == d0.count()); + + duration d1(5); + duration d1_copy(d1); + VERIFY(d1.count() * 1000 == d1_copy.count()); + + duration d2(8.0); + duration d2_copy(d2); + VERIFY(d2.count() == d2_copy.count() * 1000.0); + + duration d3(5); + duration d3_copy(d3); + VERIFY(d3.count() * 1000 == d3_copy.count()); + + duration d4(5.0); + duration d4_copy(d4); + VERIFY(d4.count() == d4_copy.count() * dbl_emulator(1000.0)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc new file mode 100644 index 00000000000..7613411879d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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 + +template class std::chrono::duration; +template class std::chrono::duration>; diff --git a/libstdc++-v3/testsuite/20_util/time_point/1.cc b/libstdc++-v3/testsuite/20_util/time_point/1.cc new file mode 100644 index 00000000000..70f4d7800eb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/1.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.4 Class template time_point [time.point] + +#include +#include + +// 20.8.4.1 time_point constructors [time.point.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point t1; + VERIFY(t1.time_since_epoch() == system_clock::duration::zero()); + + time_point t2; + VERIFY(t2.time_since_epoch() == monotonic_clock::duration::zero()); + + time_point t3; + VERIFY(t3.time_since_epoch() == high_resolution_clock::duration::zero()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/2.cc b/libstdc++-v3/testsuite/20_util/time_point/2.cc new file mode 100644 index 00000000000..91f21a5e0f7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/2.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.4 Class template time_point [time.point] + +#include +#include + +// 20.8.4.3 time_point arithmetic [time.point.arithmetic] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point t1, t2; + t1 += seconds(1); + VERIFY(t2.time_since_epoch() + seconds(1) == t1.time_since_epoch()); + + t1 -= std::chrono::seconds(1); + VERIFY(t2.time_since_epoch() == t1.time_since_epoch()); +} + +// 20.8.4.5 time_point non-member arithmetic [time.point.nonmember] +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point t1; + time_point t2(t1 + seconds(1)); + VERIFY(t2.time_since_epoch() == t1.time_since_epoch() + seconds(1)); + + time_point t3(seconds(1) + t1); + VERIFY(t3.time_since_epoch() == t1.time_since_epoch() + seconds(1)); + + time_point t4(seconds(1)); + time_point t5(seconds(2)); + + time_point t6(t5 - seconds(1)); + VERIFY(t6.time_since_epoch() == t4.time_since_epoch()); + + time_point t7(t5 - t4); + VERIFY(t7.time_since_epoch() == t4.time_since_epoch()); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/3.cc b/libstdc++-v3/testsuite/20_util/time_point/3.cc new file mode 100644 index 00000000000..20820cebea1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/3.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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. + +// 20.8.4 Class template time_point [time.point] + +#include +#include + +// 20.8.4.6 time_point comparisons [time.point.comparisons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point t1(seconds(1)); + time_point t2(seconds(1)); + time_point t3(seconds(2)); + + VERIFY(t1 == t2); + VERIFY(t1 != t3); + VERIFY(t1 < t3); + VERIFY(t1 <= t3); + VERIFY(t1 <= t2); + VERIFY(t3 > t1); + VERIFY(t3 >= t1); + VERIFY(t2 >= t1); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc new file mode 100644 index 00000000000..7f9bbdf3d16 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc @@ -0,0 +1,25 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008 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 + +template class std::chrono::time_point; -- 2.11.0