From 492a204623c3c4bbf04c9d47d69979d3a484959c Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Wed, 29 May 2019 21:36:00 +0200 Subject: [PATCH] fix bad assert --- include/fmt/chrono.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index a64a17269193..6f4824836910 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -398,9 +398,14 @@ inline bool isfinite(T value) { } template inline int to_int(T value) { FMT_ASSERT(!isnan(value), "nan to int conversion is UB"); - FMT_ASSERT((value >= (std::numeric_limits::min)() && - value <= (std::numeric_limits::max)()), - "invalid value"); + if(std::numeric_limits::is_signed) { + //this covers both float and integers + FMT_ASSERT(value >= (std::numeric_limits::min)(), + "value is too small to fit in an int"); + } + FMT_ASSERT(value <= (std::numeric_limits::max)(), + "value is too large to fit in an int"); + return static_cast(value); }