diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-08-28 23:41:13 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-08-28 23:41:13 +0100 |
commit | f2f48b68a6a586f40dd8ae0e6d391b7f88756eec (patch) | |
tree | 8fcc850276bf8a3648a74a78f4d9fb4a71a95a1e /libstdc++-v3/include/std | |
parent | 82db1a42e9254c9009bbf8ac01366da4d1ab6df5 (diff) | |
download | gcc-f2f48b68a6a586f40dd8ae0e6d391b7f88756eec.zip gcc-f2f48b68a6a586f40dd8ae0e6d391b7f88756eec.tar.gz gcc-f2f48b68a6a586f40dd8ae0e6d391b7f88756eec.tar.bz2 |
libstdc++: Fix common_type specializations for duration
My recent change to implement P0548 ("common_type and duration") was not
correct. The result of common_type_t<duration<R,P>, duration<R,P>>
should be duration<common_type_t<R>, P::type>, not duration<R, P::type>.
The common_type specialization for two different duration types was
correct, but the specializations for a single duration type (which only
exist to optimize compilation time) were wrong.
This fixes the partial specializations of common_type for a single
duration type, and also the return types of duration::operator+ and
duration::operator- which are supposed to use common_type_t<duration>.
libstdc++-v3/ChangeLog:
* include/std/chrono (common_type): Fix partial specializations
for a single duration type to use the common_type of the rep.
(duration::operator+, duration::operator-): Fix return types
to also use the common_type of the rep.
* testsuite/20_util/duration/requirements/reduced_period.cc:
Check duration using a rep that has common_type specialized.
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/chrono | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index fb25184..524d23e 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -114,13 +114,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Rep, typename _Period> struct common_type<chrono::duration<_Rep, _Period>, chrono::duration<_Rep, _Period>> - { using type = chrono::duration<_Rep, typename _Period::type>; }; + { + using type = chrono::duration<typename common_type<_Rep>::type, + typename _Period::type>; + }; /// Specialization of common_type for one chrono::duration type. /// @relates duration template<typename _Rep, typename _Period> struct common_type<chrono::duration<_Rep, _Period>> - { using type = chrono::duration<_Rep, typename _Period::type>; }; + { + using type = chrono::duration<typename common_type<_Rep>::type, + typename _Period::type>; + }; // 20.11.4.3 specialization of common_type (for time_point, sfinae-friendly) @@ -463,13 +469,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.11.5.3 arithmetic - constexpr duration<rep, period> + constexpr duration<typename common_type<rep>::type, period> operator+() const - { return *this; } + { return duration<typename common_type<rep>::type, period>(__r); } - constexpr duration<rep, period> + constexpr duration<typename common_type<rep>::type, period> operator-() const - { return duration(-__r); } + { return duration<typename common_type<rep>::type, period>(-__r); } _GLIBCXX17_CONSTEXPR duration& operator++() |