From 9f0e33bc83c2924e2af29aa76de7cbd6169dafaf Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 16 Apr 2022 07:38:10 +0700 Subject: [PATCH] fix `treat_as_floating_point_v<_DurationType>` (#2638) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Krügler Co-authored-by: Stephan T. Lavavej --- stl/inc/chrono | 14 ++++++++------ .../P0355R7_calendars_and_time_zones_io/test.cpp | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index 3cdeb670f..2d6b6a025 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -3387,14 +3387,16 @@ namespace chrono { if constexpr (_Can_rep_sec) { if (_Used & _F_sec) { if (_Subsecond) { - using _CastedType = duration; const _SubsecondType _Sub{*_Subsecond}; - if (treat_as_floating_point_v<_DurationType> // - || _CHRONO duration_cast<_CastedType>(_Sub) == _Sub) { - _Result += _CHRONO duration_cast<_DurationType>(_Sub); - } else { - return false; + + if constexpr (!treat_as_floating_point_v) { + using _CastedType = duration; + if (_CHRONO duration_cast<_CastedType>(_Sub) != _Sub) { + return false; + } } + + _Result += _CHRONO duration_cast<_DurationType>(_Sub); } if (_Second) { diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp index fd8341823..879e7a67e 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp @@ -259,6 +259,10 @@ void parse_seconds() { test_parse("0.400000000000000002", "%S", time_atto); assert((time_atto == duration{4} + duration{2})); + duration> time_float; + test_parse("0.33", "%S", time_float); + assert((time_float == duration>{8.25f})); + fail_parse("1.2 1.3", "%S %S", time_ms); fail_parse("1.2 2.2", "%S %S", time_ms); }