From: bkoz Date: Wed, 3 Nov 2010 01:59:07 +0000 (+0000) Subject: 2010-11-02 Benjamin Kosnik X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=b858c3e7c9f16ccab79a617e2fb34c51b0dc921b 2010-11-02 Benjamin Kosnik * include/std/chrono: Use typedefs. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust line numbers. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same. * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166229 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 210515f16bd..0b7d3c28660 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2010-11-02 Benjamin Kosnik + + * include/std/chrono: Use typedefs. + * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust + line numbers. + * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same. + * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same. + * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same. + 2010-11-02 Paolo Carlini * include/c_global/cmath (fpclassify, isfinite, isinf, isnan, diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 6361fdac95b..c4dcbd5f67f 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -60,7 +60,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template> struct duration; - template + template struct time_point; } @@ -69,71 +69,81 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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; + private: + typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num; + typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den; + typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef ratio<__gcd_num::value, + (_Period1::den / __gcd_den::value) * _Period2::den> __r; + + public: + typedef chrono::duration<__cr, __r> type; }; // 20.8.2.3 specialization of common_type (for time_point) - template - struct common_type, - chrono::time_point<_Clock, _Duration2>> + template + struct common_type, + chrono::time_point<_Clock, _Dur2>> { - typedef chrono::time_point<_Clock, - typename common_type<_Duration1, _Duration2>::type> type; + private: + typedef typename common_type<_Dur1, _Dur2>::type __ct; + + public: + typedef chrono::time_point<_Clock, __ct> type; }; namespace chrono { // Primary template for duration_cast impl. - template struct __duration_cast_impl { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast< - typename _ToDuration::rep>(static_cast<_CR>(__d.count()) + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_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 + struct __duration_cast_impl<_ToDur, _CF, _CR, true, true> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration( - static_cast(__d.count())); + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>(__d.count())); } }; - template - struct __duration_cast_impl<_ToDuration, _CF, _CR, true, false> + template + struct __duration_cast_impl<_ToDur, _CF, _CR, true, false> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast( + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>( static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); } }; - template - struct __duration_cast_impl<_ToDuration, _CF, _CR, false, true> + template + struct __duration_cast_impl<_ToDur, _CF, _CR, false, true> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast( + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>( static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); } }; @@ -149,18 +159,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { }; /// duration_cast - template - inline constexpr typename enable_if<__is_duration<_ToDuration>::value, - _ToDuration>::type + template + inline constexpr typename enable_if<__is_duration<_ToDur>::value, + _ToDur>::type 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); + typedef typename _ToDur::period __to_period; + typedef typename _ToDur::rep __to_rep; + typedef ratio_divide<_Period, __to_period> __r_div; + typedef typename __r_div::type __cf; + typedef typename common_type<__to_rep, _Rep, intmax_t>::type + __cr; + typedef __duration_cast_impl<_ToDur, __cf, __cr, + __cf::num == 1, __cf::den == 1> __dc; + return __dc::__cast(__d); } /// treat_as_floating_point @@ -200,8 +212,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template struct duration { - typedef _Rep rep; - typedef _Period period; + typedef _Rep rep; + typedef _Period period; static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); static_assert(__is_ratio<_Period>::value, @@ -336,8 +348,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) += __rhs; } @@ -348,8 +361,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) -= __rhs; } @@ -366,7 +380,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline duration::type, _Period> operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) *= __s; } @@ -380,7 +394,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) enable_if::value, _Rep2>::type>::type, _Period> operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) /= __s; } @@ -390,8 +404,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() / __ct(__rhs).count(); } @@ -401,7 +416,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) enable_if::value, _Rep2>::type>::type, _Period> operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) %= __s; } @@ -412,8 +427,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) %= __rhs; } @@ -424,8 +440,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() == __ct(__rhs).count(); } @@ -435,8 +452,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() < __ct(__rhs).count(); } @@ -487,13 +505,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typedef duration> hours; /// time_point - template + template struct time_point { - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; + typedef _Clock clock; + typedef _Dur duration; + typedef typename duration::rep rep; + typedef typename duration::period period; constexpr time_point() : __d(duration::zero()) { } @@ -503,8 +521,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { } // conversions - template - constexpr time_point(const time_point& __t) + template + constexpr time_point(const time_point& __t) : __d(__t.time_since_epoch()) { } @@ -542,84 +560,84 @@ _GLIBCXX_BEGIN_NAMESPACE(std) }; /// time_point_cast - template - inline constexpr typename enable_if<__is_duration<_ToDuration>::value, - time_point<_Clock, _ToDuration>>::type - time_point_cast(const time_point<_Clock, _Duration>& __t) + template + inline constexpr typename enable_if<__is_duration<_ToDur>::value, + time_point<_Clock, _ToDur>>::type + time_point_cast(const time_point<_Clock, _Dur>& __t) { - return time_point<_Clock, _ToDuration>( - duration_cast<_ToDuration>(__t.time_since_epoch())); + typedef time_point<_Clock, _ToDur> __time_point; + return __time_point(duration_cast<_ToDur>(__t.time_since_epoch())); } - template inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator+(const time_point<_Clock, _Duration1>& __lhs, + typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> + operator+(const time_point<_Clock, _Dur1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, - typename common_type<_Duration1, - duration<_Rep2, _Period2>>::type> __ct; - return __ct(__lhs) += __rhs; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<_Dur1,__dur2>::type __ct; + typedef time_point<_Clock, __ct> __time_point; + return __time_point(__lhs) += __rhs; } template + typename _Clock, typename _Dur2> inline time_point<_Clock, - typename common_type, _Duration2>::type> + typename common_type, _Dur2>::type> operator+(const duration<_Rep1, _Period1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Dur2>& __rhs) { return __rhs + __lhs; } - template inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator-(const time_point<_Clock, _Duration1>& __lhs, + typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> + operator-(const time_point<_Clock, _Dur1>& __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) + template + inline typename common_type<_Dur1, _Dur2>::type + operator-(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator==(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator==(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator!=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator!=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__lhs == __rhs); } - template + template inline constexpr bool - operator<(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator<(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator<=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator<=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__rhs < __lhs); } - template + template inline constexpr bool - operator>(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator>(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __rhs < __lhs; } - template + template inline constexpr bool - operator>=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator>=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__lhs < __rhs); } /// system_clock @@ -650,16 +668,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) static std::time_t to_time_t(const time_point& __t) { - return std::time_t( - duration_cast(__t.time_since_epoch()).count()); + 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))); + typedef chrono::time_point __from; + return time_point_cast + (__from(chrono::seconds(__t))); } }; diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc index aae7e04c861..e33c5131f4a 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc @@ -31,5 +31,5 @@ void test01() test_type d; } -// { dg-error "rep cannot be a duration" "" { target *-*-* } 206 } +// { dg-error "rep cannot be a duration" "" { target *-*-* } 218 } // { dg-error "instantiated from here" "" { target *-*-* } 31 } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc index 33ae9d57d00..a865effb6dd 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc @@ -32,6 +32,6 @@ void test01() test_type d; } -// { dg-error "must be a specialization of ratio" "" { target *-*-* } 207 } +// { dg-error "must be a specialization of ratio" "" { target *-*-* } 219 } // { dg-error "instantiated from here" "" { target *-*-* } 32 } // { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc index 4faf93a4873..c168357edd1 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc @@ -33,5 +33,5 @@ void test01() test_type d; } -// { dg-error "period must be positive" "" { target *-*-* } 209 } +// { dg-error "period must be positive" "" { target *-*-* } 221 } // { dg-error "instantiated from here" "" { target *-*-* } 33 } diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc index c7617690fe2..fa4c85ee77e 100644 --- a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc @@ -51,6 +51,7 @@ test04() // { dg-error "instantiated from here" "" { target *-*-* } 46 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 153 } // { dg-error "out of range" "" { target *-*-* } 154 } -// { dg-error "constant expression" "" { target *-*-* } 59 } +// { dg-error "non-constant expression" "" { target *-*-* } 59 } +// { dg-error "is not a constant expression" "" { target *-*-* } 59 } // { dg-error "not a member" "" { target *-*-* } 162 } // { dg-error "not a valid template argument" "" { target *-*-* } 164 }