diff --git a/libcxx/include/chrono b/libcxx/include/chrono index 4e82ef2b5f46..657808736d09 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -48,7 +48,7 @@ class duration static_assert(Period::num > 0, "duration period must be positive"); public: typedef Rep rep; - typedef Period period; + typedef typename _Period::type period; constexpr duration() = default; template @@ -75,8 +75,8 @@ public: // arithmetic - constexpr duration operator+() const; - constexpr duration operator-() const; + constexpr common_type::type operator+() const; + constexpr common_type::type operator-() const; constexpr duration& operator++(); constexpr duration operator++(int); constexpr duration& operator--(); @@ -523,7 +523,7 @@ class _LIBCPP_TEMPLATE_VIS duration public: typedef _Rep rep; - typedef _Period period; + typedef typename _Period::type period; private: rep __rep_; public: @@ -565,8 +565,8 @@ public: // arithmetic - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator+() const {return typename common_type::type(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator-() const {return typename common_type::type(-__rep_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 3aa84605aed8..8facb3bb9459 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -1958,7 +1958,7 @@ template struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, void, void> { public: - typedef typename decay<_Tp>::type type; + typedef typename common_type<_Tp, _Tp>::type type; }; template @@ -1981,7 +1981,7 @@ struct _LIBCPP_TEMPLATE_VIS common_type {}; template struct _LIBCPP_TEMPLATE_VIS common_type<_Tp> { - typedef typename decay<_Tp>::type type; + typedef typename common_type<_Tp, _Tp>::type type; }; // bullet 3 - sizeof...(Tp) == 2 diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp index 61523e4872d4..736f74b4c270 100644 --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -37,6 +37,12 @@ namespace std typedef S type; }; +// P0548 + template + struct common_type< ::S, ::S > { + typedef S type; + }; + template <> struct common_type< ::S, long> {}; template <> struct common_type > {}; } @@ -284,4 +290,19 @@ int main() test_bullet_three_two(); test_bullet_four(); #endif + +// P0548 + static_assert((std::is_same >::type, S >::value), ""); + static_assert((std::is_same, S >::type, S >::value), ""); + + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + static_assert((std::is_same::type, int>::value), ""); + } diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp index c0f10147ee89..e4a22cfadfba 100644 --- a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -11,11 +11,13 @@ // duration -// duration operator+() const; +// constexpr common_type_t operator+() const; #include #include +#include + int main() { { @@ -23,7 +25,7 @@ int main() std::chrono::minutes m2 = +m; assert(m.count() == m2.count()); } -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#if TEST_STD_VER >= 11 { constexpr std::chrono::minutes m(3); constexpr std::chrono::minutes m2 = +m; diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp index 00da6f69ca53..bc1328c9df50 100644 --- a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -11,11 +11,13 @@ // duration -// duration operator-() const; +// constexpr common_type_t operator-() const; #include #include +#include + int main() { { @@ -23,11 +25,23 @@ int main() std::chrono::minutes m2 = -m; assert(m2.count() == -m.count()); } -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#if TEST_STD_VER >= 11 { constexpr std::chrono::minutes m(3); constexpr std::chrono::minutes m2 = -m; static_assert(m2.count() == -m.count(), ""); } #endif + +// P0548 + { + typedef std::chrono::duration > D10; + typedef std::chrono::duration > D1; + D10 zero{0}; + D10 one{1}; + static_assert( (std::is_same< decltype(-one), decltype(zero-one) >::value), ""); + static_assert( (std::is_same< decltype(zero-one), D1>::value), ""); + static_assert( (std::is_same< decltype(-one), D1>::value), ""); + static_assert( (std::is_same< decltype(+one), D1>::value), ""); + } } diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index f3cffb79b242..906585f95435 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -153,7 +153,7 @@ P0492R2LWGProposed Resolution of C++17 National Body Comments for FilesystemsKona P0518R1LWGAllowing copies as arguments to function objects given to parallel algorithms in response to CH11Kona P0523R1LWGWording for CH 10: Complexity of parallel algorithmsKona - P0548R1LWGcommon_type and durationKona + P0548R1LWGcommon_type and durationKonaComplete5.0 P0558R1LWGResolving atomic<T> named base class inconsistenciesKona P0574R1LWGAlgorithm Complexity Constraints and Parallel OverloadsKona P0599R1LWGnoexcept for hash functionsKona