From 1e83906211ebe4583989a6e428c5c4afa7b8df46 Mon Sep 17 00:00:00 2001 From: Philipp Kerling Date: Mon, 27 Jan 2025 18:02:59 +0100 Subject: [PATCH 1/2] Fix chrono duration operator/ and % enable_if The (duration, number) overloads of operator/ and operator% shall not participate in overload resolution if Rep2 is a duration. Fixes #555. --- include/EASTL/chrono.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/EASTL/chrono.h b/include/EASTL/chrono.h index 024e8098..9ec3dbb0 100644 --- a/include/EASTL/chrono.h +++ b/include/EASTL/chrono.h @@ -327,7 +327,12 @@ namespace chrono } template - duration::type, Period1> EASTL_FORCE_INLINE + duration< + typename eastl::common_type< + Rep1, + typename eastl::enable_if::value, Rep2>::type + >::type, + Period1> EASTL_FORCE_INLINE operator/(const duration& lhs, const Rep2& rhs) { typedef duration::type, Period1> common_duration_t; @@ -343,7 +348,12 @@ namespace chrono } template - duration::type, Period1> EASTL_FORCE_INLINE + duration< + typename eastl::common_type< + Rep1, + typename eastl::enable_if::value, Rep2>::type + >::type, + Period1> EASTL_FORCE_INLINE operator%(const duration& lhs, const Rep2& rhs) { typedef duration::type, Period1> common_duration_t; From 99da32e76fa45546f9614bbb3f3743d7a88dc13d Mon Sep 17 00:00:00 2001 From: Philipp Kerling Date: Tue, 28 Jan 2025 11:42:33 +0100 Subject: [PATCH 2/2] Fix operator/(duration, duration) return type Dividing two durations shall yield a dimensionless number and not a duration. Fixes #554. --- include/EASTL/chrono.h | 4 ++-- test/source/TestChrono.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/EASTL/chrono.h b/include/EASTL/chrono.h index 9ec3dbb0..18bfd355 100644 --- a/include/EASTL/chrono.h +++ b/include/EASTL/chrono.h @@ -340,11 +340,11 @@ namespace chrono } template - typename eastl::common_type, duration>::type EASTL_FORCE_INLINE + typename eastl::common_type::type EASTL_FORCE_INLINE operator/(const duration& lhs, const duration& rhs) { typedef typename eastl::common_type, duration>::type common_duration_t; - return common_duration_t(common_duration_t(lhs).count() / common_duration_t(rhs).count()); + return common_duration_t(lhs).count() / common_duration_t(rhs).count(); } template diff --git a/test/source/TestChrono.cpp b/test/source/TestChrono.cpp index a56b9343..9340d800 100644 --- a/test/source/TestChrono.cpp +++ b/test/source/TestChrono.cpp @@ -101,6 +101,13 @@ int TestDuration() } } + { + seconds s(5); + milliseconds ms(10); + VERIFY(s / ms == 500); + VERIFY(ms / s.count() == milliseconds(2)); + } + return nErrorCount; }