From 84eea802efb1164c4f2a83b2e480a7c5bdf4e921 Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Mon, 17 Jun 2019 19:45:22 +0200 Subject: [PATCH] review comment: turn cmake option into macro for SAFE_DURATION_CAST decided to have it on by default --- CMakeLists.txt | 1 - include/fmt/chrono.h | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 628ed8d35df8..0c95073df565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ endif () option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_WERROR "Halt the compilation with an error on compiler warnings." OFF) -option(FMT_SAFE_DURATION_CAST "verify chrono duration casts" OFF) # Options that control generation of various targets. option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT}) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index df653b5ef230..fe514fac5f5e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -16,7 +16,12 @@ #include #include -#ifdef FMT_SAFE_DURATION_CAST +// enable safe chrono durations, unless explicitly disabled +#ifndef FMT_SAFE_DURATION_CAST +# define FMT_SAFE_DURATION_CAST 1 +#endif + +#if FMT_SAFE_DURATION_CAST # include "safe-duration-cast.h" #endif @@ -438,7 +443,7 @@ inline std::chrono::duration get_milliseconds( std::chrono::duration d) { // this may overflow and/or the result may not fit in the // target type. -#ifdef FMT_SAFE_DURATION_CAST +#if FMT_SAFE_DURATION_CAST // if(std::ratio_less>::value) { using CommonSecondsType = typename std::common_type::type; @@ -519,7 +524,7 @@ struct chrono_formatter { // this may overflow and/or the result may not fit in the // target type. -#ifdef FMT_SAFE_DURATION_CAST +#if FMT_SAFE_DURATION_CAST int ec; // might need checked conversion (rep!=Rep) auto tmpval = std::chrono::duration(val); @@ -663,7 +668,7 @@ struct chrono_formatter { if (ns == numeric_system::standard) { write(second(), 2); -#ifdef FMT_SAFE_DURATION_CAST +#if FMT_SAFE_DURATION_CAST int ec; // convert rep->Rep using Crep = std::chrono::duration;