diff --git a/include/json/value.h b/include/json/value.h index e1340d6..c972924 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -203,31 +203,33 @@ public: static Value const& nullSingleton(); /// Minimum signed integer value that can be stored in a Json::Value. - static const LargestInt minLargestInt; + static constexpr LargestInt minLargestInt = LargestInt(~(LargestUInt(-1) / 2)); /// Maximum signed integer value that can be stored in a Json::Value. - static const LargestInt maxLargestInt; + static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2); /// Maximum unsigned integer value that can be stored in a Json::Value. - static const LargestUInt maxLargestUInt; + static constexpr LargestUInt maxLargestUInt = LargestUInt(-1); /// Minimum signed int value that can be stored in a Json::Value. - static const Int minInt; + static constexpr Int minInt = Int(~(UInt(-1) / 2)); /// Maximum signed int value that can be stored in a Json::Value. - static const Int maxInt; + static constexpr Int maxInt = Int(UInt(-1) / 2); /// Maximum unsigned int value that can be stored in a Json::Value. - static const UInt maxUInt; + static constexpr UInt maxUInt = UInt(-1); #if defined(JSON_HAS_INT64) /// Minimum signed 64 bits int value that can be stored in a Json::Value. - static const Int64 minInt64; + static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2)); /// Maximum signed 64 bits int value that can be stored in a Json::Value. - static const Int64 maxInt64; + static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2); /// Maximum unsigned 64 bits int value that can be stored in a Json::Value. - static const UInt64 maxUInt64; + static constexpr UInt64 maxUInt64 = UInt64(-1); #endif // defined(JSON_HAS_INT64) - /// Default precision for real value for string representation. - static const UInt defaultRealPrecision; - + static constexpr UInt defaultRealPrecision = 17; + // The constant is hard-coded because some compiler have trouble + // converting Value::maxUInt64 to a double correctly (AIX/xlC). + // Assumes that UInt64 is a 64 bits integer. + static constexpr double maxUInt64AsDouble = 18446744073709551615.0; // Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler // when using gcc and clang backend compilers. CZString // cannot be defined as private. See issue #486 diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 1d614a4..87e9c67 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1548,12 +1548,11 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) { if (isNegative) ++current; - // TODO(issue #960): Change to constexpr - static const auto positive_threshold = Value::maxLargestUInt / 10; - static const auto positive_last_digit = Value::maxLargestUInt % 10; - static const auto negative_threshold = + static constexpr auto positive_threshold = Value::maxLargestUInt / 10; + static constexpr auto positive_last_digit = Value::maxLargestUInt % 10; + static constexpr auto negative_threshold = Value::LargestUInt(Value::minLargestInt) / 10; - static const auto negative_last_digit = + static constexpr auto negative_last_digit = Value::LargestUInt(Value::minLargestInt) % 10; const auto threshold = isNegative ? negative_threshold : positive_threshold; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 6024212..771c0dc 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -88,23 +88,6 @@ Value const& Value::null = Value::nullSingleton(); Value const& Value::nullRef = Value::nullSingleton(); #endif -const Int Value::minInt = Int(~(UInt(-1) / 2)); -const Int Value::maxInt = Int(UInt(-1) / 2); -const UInt Value::maxUInt = UInt(-1); -#if defined(JSON_HAS_INT64) -const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2)); -const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2); -const UInt64 Value::maxUInt64 = UInt64(-1); -// The constant is hard-coded because some compiler have trouble -// converting Value::maxUInt64 to a double correctly (AIX/xlC). -// Assumes that UInt64 is a 64 bits integer. -static const double maxUInt64AsDouble = 18446744073709551615.0; -#endif // defined(JSON_HAS_INT64) -const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2)); -const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2); -const LargestUInt Value::maxLargestUInt = LargestUInt(-1); - -const UInt Value::defaultRealPrecision = 17; #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) template