diff --git a/libcxx/include/chrono b/libcxx/include/chrono index 0571f9dff7e4..3900d59af78c 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -20,6 +20,7 @@ namespace chrono { template +constexpr ToDuration duration_cast(const duration& fd); @@ -29,9 +30,9 @@ template struct duration_values { public: - static Rep zero(); - static Rep max(); - static Rep min(); + static constexpr Rep zero(); + static constexpr Rep max(); + static constexpr Rep min(); }; // duration @@ -46,9 +47,9 @@ public: typedef Rep rep; typedef Period period; - duration() = default; + constexpr duration() = default; template - explicit duration(const Rep2& r, + constexpr explicit duration(const Rep2& r, typename enable_if < is_convertible::value && @@ -58,7 +59,7 @@ public: // conversions template - duration(const duration& d, + constexpr duration(const duration& d, typename enable_if < treat_as_floating_point::value || @@ -67,12 +68,12 @@ public: // observer - rep count() const; + constexpr rep count() const; // arithmetic - duration operator+() const; - duration operator-() const; + constexpr duration operator+() const; + constexpr duration operator-() const; duration& operator++(); duration operator++(int); duration& operator--(); @@ -86,9 +87,9 @@ public: // special values - static duration zero(); - static duration min(); - static duration max(); + static constexpr duration zero(); + static constexpr duration min(); + static constexpr duration max(); }; typedef duration nanoseconds; @@ -145,36 +146,48 @@ namespace chrono { // duration arithmetic template + constexpr typename common_type, duration>::type operator+(const duration& lhs, const duration& rhs); template + constexpr typename common_type, duration>::type operator-(const duration& lhs, const duration& rhs); template + constexpr duration::type, Period> operator*(const duration& d, const Rep2& s); template + constexpr duration::type, Period> operator*(const Rep1& s, const duration& d); template + constexpr duration::type, Period> operator/(const duration& d, const Rep2& s); template + constexpr typename common_type::type operator/(const duration& lhs, const duration& rhs); // duration comparisons template + constexpr bool operator==(const duration& lhs, const duration& rhs); template + constexpr bool operator!=(const duration& lhs, const duration& rhs); template + constexpr bool operator< (const duration& lhs, const duration& rhs); template + constexpr bool operator<=(const duration& lhs, const duration& rhs); template + constexpr bool operator> (const duration& lhs, const duration& rhs); template + constexpr bool operator>=(const duration& lhs, const duration& rhs); // duration_cast @@ -306,7 +319,7 @@ struct __duration_cast; template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { return _ToDuration(static_cast(__fd.count())); @@ -316,7 +329,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; @@ -328,7 +341,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; @@ -340,7 +353,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; @@ -352,6 +365,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, @@ -369,9 +383,9 @@ template struct _LIBCPP_VISIBLE duration_values { public: - _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);} - _LIBCPP_INLINE_VISIBILITY static _Rep max() {return numeric_limits<_Rep>::max();} - _LIBCPP_INLINE_VISIBILITY static _Rep min() {return numeric_limits<_Rep>::lowest();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} }; // duration @@ -389,9 +403,9 @@ private: rep __rep_; public: - _LIBCPP_INLINE_VISIBILITY duration() {} // = default; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default; template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r, typename enable_if < @@ -403,7 +417,7 @@ public: // conversions template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration(const duration<_Rep2, _Period2>& __d, typename enable_if < @@ -415,12 +429,12 @@ public: // observer - _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} // arithmetic - _LIBCPP_INLINE_VISIBILITY duration operator+() const {return *this;} - _LIBCPP_INLINE_VISIBILITY duration operator-() const {return duration(-__rep_);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);} _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;} _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);} _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;} @@ -436,9 +450,9 @@ public: // special values - _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values::zero());} - _LIBCPP_INLINE_VISIBILITY static duration min() {return duration(duration_values::min());} - _LIBCPP_INLINE_VISIBILITY static duration max() {return duration(duration_values::max());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values::zero());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values::min());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values::max());} }; typedef duration nanoseconds; @@ -453,7 +467,7 @@ typedef duration< long, ratio<3600> > hours; template struct __duration_eq { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; @@ -464,13 +478,14 @@ struct __duration_eq template struct __duration_eq<_LhsDuration, _LhsDuration> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) {return __lhs.count() == __rhs.count();} }; template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -481,6 +496,7 @@ operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -492,7 +508,7 @@ operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template struct __duration_lt { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; @@ -503,13 +519,14 @@ struct __duration_lt template struct __duration_lt<_LhsDuration, _LhsDuration> { - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) {return __lhs.count() < __rhs.count();} }; template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -520,6 +537,7 @@ operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -530,6 +548,7 @@ operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -540,6 +559,7 @@ operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -550,30 +570,31 @@ operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; - __r += __rhs; - return __r; + typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); } // Duration - template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; - __r -= __rhs; - return __r; + typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); } // Duration * template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if < is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, @@ -582,13 +603,13 @@ typename enable_if operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; - duration<_Cr, _Period> __r = __d; - __r *= static_cast<_Cr>(__s); - return __r; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if < is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, @@ -627,17 +648,18 @@ struct __duration_divide_result, _Rep2, false> template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename __duration_divide_result, _Rep2>::type operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; - duration<_Cr, _Period> __r = __d; - __r /= static_cast<_Cr>(__s); - return __r; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename common_type<_Rep1, _Rep2>::type operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -649,23 +671,24 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2 template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename __duration_divide_result, _Rep2>::type operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; - duration<_Cr, _Period> __r = __d; - __r %= static_cast<_Cr>(__s); - return __r; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; - __r %= __rhs; - return __r; + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); } ////////////////////////////////////////////////////////// @@ -710,8 +733,8 @@ public: // special values - _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());} - _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());} }; } // chrono diff --git a/libcxx/test/utilities/time/rep.h b/libcxx/test/utilities/time/rep.h index ea4db2d3f210..59c58bbb7e1e 100644 --- a/libcxx/test/utilities/time/rep.h +++ b/libcxx/test/utilities/time/rep.h @@ -5,11 +5,11 @@ class Rep { int data_; public: - Rep() : data_(-1) {} - explicit Rep(int i) : data_(i) {} + _LIBCPP_CONSTEXPR Rep() : data_(-1) {} + explicit _LIBCPP_CONSTEXPR Rep(int i) : data_(i) {} - bool operator==(int i) const {return data_ == i;} - bool operator==(const Rep& r) const {return data_ == r.data_;} + bool _LIBCPP_CONSTEXPR operator==(int i) const {return data_ == i;} + bool _LIBCPP_CONSTEXPR operator==(const Rep& r) const {return data_ == r.data_;} Rep& operator*=(Rep x) {data_ *= x.data_; return *this;} Rep& operator/=(Rep x) {data_ /= x.data_; return *this;} diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp index 3103b238c96a..c0f10147ee89 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -18,7 +18,16 @@ int main() { + { const std::chrono::minutes m(3); std::chrono::minutes m2 = +m; assert(m.count() == m2.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = +m; + static_assert(m.count() == m2.count(), ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp index aa7f74813b64..00da6f69ca53 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -18,7 +18,16 @@ int main() { + { const std::chrono::minutes m(3); std::chrono::minutes m2 = -m; assert(m2.count() == -m.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = -m; + static_assert(m2.count() == -m.count(), ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp index 053ab9980ab4..1c87fcd909ef 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // ToDuration // duration_cast(const duration& d); @@ -23,9 +24,11 @@ template void test(const FromDuration& f, const ToDuration& d) { + { typedef decltype(std::chrono::duration_cast(f)) R; static_assert((std::is_same::value), ""); assert(std::chrono::duration_cast(f) == d); + } } int main() @@ -40,4 +43,10 @@ int main() std::chrono::duration >(7265./3600)); test(std::chrono::duration >(9), std::chrono::duration >(10)); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::hours h = std::chrono::duration_cast(std::chrono::milliseconds(7265000)); + static_assert(h.count() == 2, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp index 154d43dc0c8e..2d0dd94d4cf6 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp @@ -12,10 +12,12 @@ // duration // template +// constexpr // bool // operator==(const duration& lhs, const duration& rhs); // template +// constexpr // bool // operator!=(const duration& lhs, const duration& rhs); @@ -66,4 +68,48 @@ int main() assert(s1 == s2); assert(!(s1 != s2)); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration > s1(9); + constexpr std::chrono::duration > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::duration > s1(10); + constexpr std::chrono::duration > s2(9); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration > s1(9); + constexpr std::chrono::duration > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp index daf7e89a5aad..9d875579f326 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp @@ -12,18 +12,22 @@ // duration // template +// constexpr // bool // operator< (const duration& lhs, const duration& rhs); // template +// constexpr // bool // operator> (const duration& lhs, const duration& rhs); // template +// constexpr // bool // operator<=(const duration& lhs, const duration& rhs); // template +// constexpr // bool // operator>=(const duration& lhs, const duration& rhs); @@ -88,4 +92,62 @@ int main() assert( (s1 <= s2)); assert( (s1 >= s2)); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::duration > s1(9); + constexpr std::chrono::duration > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration > s1(10); + constexpr std::chrono::duration > s2(9); + static_assert(!(s1 < s2), ""); + static_assert( (s1 > s2), ""); + static_assert(!(s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration > s1(9); + constexpr std::chrono::duration > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp index e7380f72d745..152227d82a82 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp @@ -21,7 +21,16 @@ int main() { + { std::chrono::milliseconds ms(1); std::chrono::microseconds us = ms; assert(us.count() == 1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::milliseconds ms(1); + constexpr std::chrono::microseconds us = ms; + static_assert(us.count() == 1000, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp index 0eba13a6fbaa..519b2b141c29 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp @@ -21,7 +21,16 @@ int main() { + { std::chrono::duration us(1); std::chrono::duration ms = us; assert(ms.count() == 1./1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration us(1); + constexpr std::chrono::duration ms = us; + static_assert(ms.count() == 1./1000, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp index 1095cf32450f..59fefe2e002d 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp @@ -21,7 +21,16 @@ int main() { + { std::chrono::duration i(3); - std::chrono::duration d = i; - assert(d.count() == 3); + std::chrono::duration d = i; + assert(d.count() == 3000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration i(3); + constexpr std::chrono::duration d = i; + static_assert(d.count() == 3000, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp index 6e048b2ab307..837f43721223 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/default.pass.cpp @@ -26,6 +26,10 @@ test() { D d; assert(d.count() == typename D::rep()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2; + static_assert(d2.count() == typename D::rep(), ""); +#endif } int main() diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp index 9879568107f7..20f81619bd12 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep.pass.cpp @@ -25,6 +25,10 @@ test(R r) { D d(r); assert(d.count() == r); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2(R(2)); + static_assert(d2.count() == 2, ""); +#endif } int main() diff --git a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp index c34a4ffc86c7..b3ba9f7081e4 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp @@ -23,4 +23,8 @@ int main() { std::chrono::duration d(5); assert(d.count() == 5); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr std::chrono::duration d2(5); + static_assert(d2.count() == 5, ""); +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp index d2c194ee7424..6585351cb4c8 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp @@ -44,4 +44,30 @@ int main() std::chrono::duration > r = s1 + s2; assert(r.count() == 75); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 + s2; + static_assert(r.count() == 8, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 + s2; + static_assert(r.count() == 3000005, ""); + } + { + constexpr std::chrono::duration > s1(3); + constexpr std::chrono::duration > s2(5); + constexpr std::chrono::duration > r = s1 + s2; + static_assert(r.count() == 75, ""); + } + { + constexpr std::chrono::duration > s1(3); + constexpr std::chrono::duration > s2(5); + constexpr std::chrono::duration > r = s1 + s2; + static_assert(r.count() == 75, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp index 44185435fb45..fac58b9716d3 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // typename common_type, duration>::type // operator-(const duration& lhs, const duration& rhs); @@ -44,4 +45,30 @@ int main() std::chrono::duration > r = s1 - s2; assert(r.count() == -15); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 - s2; + static_assert(r.count() == -2, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 - s2; + static_assert(r.count() == 2999995, ""); + } + { + constexpr std::chrono::duration > s1(3); + constexpr std::chrono::duration > s2(5); + constexpr std::chrono::duration > r = s1 - s2; + static_assert(r.count() == -15, ""); + } + { + constexpr std::chrono::duration > s1(3); + constexpr std::chrono::duration > s2(5); + constexpr std::chrono::duration > r = s1 - s2; + static_assert(r.count() == -15, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp index d41340431dad..6b24676f100c 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // typename common_type::type // operator/(const duration& lhs, const duration& rhs); @@ -40,4 +41,26 @@ int main() std::chrono::duration > s2(5); assert(s1 / s2 == 20./3); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(ns1 / ns2 == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(us1 / ns2 == 3000, ""); + } + { + constexpr std::chrono::duration > s1(30); + constexpr std::chrono::duration > s2(5); + static_assert(s1 / s2 == 6, ""); + } + { + constexpr std::chrono::duration > s1(30); + constexpr std::chrono::duration > s2(5); + static_assert(s1 / s2 == 20./3, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp index 2245e92e4adb..3036cde5bf67 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // duration::type, Period> // operator/(const duration& d, const Rep2& s); @@ -20,7 +21,16 @@ int main() { + { std::chrono::nanoseconds ns(15); ns = ns / 5; assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns / 5; + static_assert(ns2.count() == 3, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp index 99f8c59ae4fe..e69f3205d14f 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // typename common_type, duration>::type // operator%(const duration& lhs, const duration& rhs); @@ -38,4 +39,24 @@ int main() std::chrono::duration > r = s1 % s2; assert(r.count() == 24); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(6); + constexpr std::chrono::nanoseconds r = ns1 % ns2; + static_assert(r.count() == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(28); + constexpr std::chrono::nanoseconds r = us1 % ns2; + static_assert(r.count() == 20, ""); + } + { + constexpr std::chrono::duration > s1(6); + constexpr std::chrono::duration > s2(3); + constexpr std::chrono::duration > r = s1 % s2; + static_assert(r.count() == 24, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp index 4b379a099620..1acbe34ea5eb 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp @@ -12,6 +12,7 @@ // duration // template +// constexpr // duration::type, Period> // operator%(const duration& d, const Rep2& s) @@ -20,7 +21,16 @@ int main() { + { std::chrono::nanoseconds ns(15); ns = ns % 6; assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns % 6; + static_assert(ns2.count() == 3, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp index ecfe7a944a33..190e74b1dc32 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp @@ -12,10 +12,12 @@ // duration // template +// constexpr // duration::type, Period> // operator*(const duration& d, const Rep2& s); // template +// constexpr // duration::type, Period> // operator*(const Rep1& s, const duration& d); @@ -24,9 +26,20 @@ int main() { + { std::chrono::nanoseconds ns(3); ns = ns * 5; assert(ns.count() == 15); ns = 6 * ns; assert(ns.count() == 90); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(3); + constexpr std::chrono::nanoseconds ns2 = ns * 5; + static_assert(ns2.count() == 15, ""); + constexpr std::chrono::nanoseconds ns3 = 6 * ns; + static_assert(ns3.count() == 18, ""); + } +#endif } diff --git a/libcxx/test/utilities/time/time.duration/time.duration.special/max.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.special/max.pass.cpp index a9e60d75df26..405461e88ae9 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.special/max.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.special/max.pass.cpp @@ -22,9 +22,18 @@ template void test() { + { typedef typename D::rep Rep; Rep max_rep = std::chrono::duration_values::max(); assert(D::max().count() == max_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep max_rep = std::chrono::duration_values::max(); + static_assert(D::max().count() == max_rep, ""); + } +#endif } int main() diff --git a/libcxx/test/utilities/time/time.duration/time.duration.special/min.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.special/min.pass.cpp index e32fe0b80811..44cd64eff3d3 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.special/min.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.special/min.pass.cpp @@ -22,9 +22,18 @@ template void test() { + { typedef typename D::rep Rep; Rep min_rep = std::chrono::duration_values::min(); assert(D::min().count() == min_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep min_rep = std::chrono::duration_values::min(); + static_assert(D::min().count() == min_rep, ""); + } +#endif } int main() diff --git a/libcxx/test/utilities/time/time.duration/time.duration.special/zero.pass.cpp b/libcxx/test/utilities/time/time.duration/time.duration.special/zero.pass.cpp index c919ad88c71f..18350fe2ff47 100644 --- a/libcxx/test/utilities/time/time.duration/time.duration.special/zero.pass.cpp +++ b/libcxx/test/utilities/time/time.duration/time.duration.special/zero.pass.cpp @@ -21,9 +21,18 @@ template void test() { + { typedef typename D::rep Rep; Rep zero_rep = std::chrono::duration_values::zero(); assert(D::zero().count() == zero_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep zero_rep = std::chrono::duration_values::zero(); + static_assert(D::zero().count() == zero_rep, ""); + } +#endif } int main() diff --git a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp index 24084160010f..89dc1dcc1a59 100644 --- a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp +++ b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp @@ -25,4 +25,12 @@ int main() std::numeric_limits::max()); assert(std::chrono::duration_values::max() == std::numeric_limits::max()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values::max() == + std::numeric_limits::max(), ""); + static_assert(std::chrono::duration_values::max() == + std::numeric_limits::max(), ""); + static_assert(std::chrono::duration_values::max() == + std::numeric_limits::max(), ""); +#endif } diff --git a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp index 420cbb4d5382..69812bba006a 100644 --- a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp +++ b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp @@ -25,4 +25,12 @@ int main() std::numeric_limits::lowest()); assert(std::chrono::duration_values::min() == std::numeric_limits::lowest()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values::min() == + std::numeric_limits::lowest(), ""); + static_assert(std::chrono::duration_values::min() == + std::numeric_limits::lowest(), ""); + static_assert(std::chrono::duration_values::min() == + std::numeric_limits::lowest(), ""); +#endif } diff --git a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp index 2a6e90fb17c1..234b4bc31c9d 100644 --- a/libcxx/test/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp +++ b/libcxx/test/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp @@ -20,4 +20,8 @@ int main() { assert(std::chrono::duration_values::zero() == 0); assert(std::chrono::duration_values::zero() == 0); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values::zero() == 0, ""); + static_assert(std::chrono::duration_values::zero() == 0, ""); +#endif }