Fixed a problem that some compilers did not allow `inline constexpr` local variable declarations (https://github.com/jtv/libpqxx/pull/468). diff --git a/src/strconv.cxx b/src/strconv.cxx index 57188dee..0eba014b 100644 --- a/src/strconv.cxx +++ b/src/strconv.cxx @@ -317,6 +317,20 @@ namespace "Could not convert string to integer: value out of range."}; } +template struct numeric_ten +{ + static inline constexpr T value = 10; +}; + +template struct numeric_high_threshold +{ + static inline constexpr T value = (std::numeric_limits::max)() / numeric_ten::value; +}; + +template struct numeric_low_threshold +{ + static inline constexpr T value = (std::numeric_limits::min)() / numeric_ten::value; +}; /// Return 10*n, or throw exception if it overflows. template @@ -324,19 +338,16 @@ template { using limits = std::numeric_limits; - inline constexpr T ten{10}; - inline constexpr T high_threshold(std::numeric_limits::max() / ten); - if (n > high_threshold) + if (n > numeric_high_threshold::value) PQXX_UNLIKELY report_overflow(); if constexpr (limits::is_signed) { - inline constexpr T low_threshold(std::numeric_limits::min() / ten); - if (low_threshold > n) + if (numeric_low_threshold::value > n) PQXX_UNLIKELY report_overflow(); } - return T(n * ten); + return T(n * numeric_ten::value); }