diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index 186b62ef1..93837baa6 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -196,7 +196,7 @@ boundaries compute_boundaries(FloatType value) constexpr int kMinExp = 1 - kBias; constexpr uint64_t kHiddenBit = uint64_t{1} << (kPrecision - 1); // = 2^(p-1) - using bits_type = typename std::conditional< kPrecision == 24, uint32_t, uint64_t >::type; + using bits_type = typename std::conditional::type; const uint64_t bits = reinterpret_bits(value); const uint64_t E = bits >> (kPrecision - 1); @@ -607,7 +607,10 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, // = ((p1 ) * 2^-e + (p2 )) * 2^e // = p1 + p2 * 2^e - const diyfp one(uint64_t{1} << -M_plus.e, M_plus.e); + const diyfp one(uint64_t + { + 1 + } << -M_plus.e, M_plus.e); uint32_t p1 = static_cast(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 19ab9894a..c0f817766 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -414,7 +414,7 @@ class serializer else { // we finish reading, but do not accept: string was incomplete - std::string sn(3,'\0'); + std::string sn(3, '\0'); snprintf(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f5b93632f..dedd2edc2 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -7667,7 +7667,7 @@ struct hash /// @note: do not remove the space after '<', /// see https://github.com/nlohmann/json/pull/679 template<> -struct less< ::nlohmann::detail::value_t> +struct less<::nlohmann::detail::value_t> { /*! @brief compare two value_t enum values diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2b387a8b6..5191b474d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -1973,10 +1973,8 @@ class input_adapter #include // localeconv #include // size_t #include // strtof, strtod, strtold, strtoll, strtoull +#include // snprintf #include // initializer_list -#include // hex, uppercase -#include // setw, setfill -#include // stringstream #include // char_traits, string #include // vector @@ -3146,10 +3144,9 @@ scan_number_done: if ('\x00' <= c and c <= '\x1F') { // escape control characters - std::stringstream ss; - ss << "(c) << ">"; - result += ss.str(); + char cs[9]; + snprintf(cs, 9, "", c); + result += cs; } else { @@ -5619,12 +5616,10 @@ class output_adapter #include // ldexp #include // size_t #include // uint8_t, uint16_t, uint32_t, uint64_t +#include // snprintf #include // memcpy -#include // setw, setfill -#include // hex #include // back_inserter #include // numeric_limits -#include // stringstream #include // char_traits, string #include // make_pair, move @@ -7283,9 +7278,9 @@ class binary_reader */ std::string get_token_string() const { - std::stringstream ss; - ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current; - return ss.str(); + char cr[3]; + snprintf(cr, 3, "%.2X", current); + return std::string{cr}; } private: @@ -8272,11 +8267,8 @@ class binary_writer #include // size_t, ptrdiff_t #include // uint8_t #include // snprintf -#include // setfill -#include // next #include // numeric_limits #include // string -#include // stringstream #include // is_same // #include @@ -8480,7 +8472,7 @@ boundaries compute_boundaries(FloatType value) constexpr int kMinExp = 1 - kBias; constexpr uint64_t kHiddenBit = uint64_t{1} << (kPrecision - 1); // = 2^(p-1) - using bits_type = typename std::conditional< kPrecision == 24, uint32_t, uint64_t >::type; + using bits_type = typename std::conditional::type; const uint64_t bits = reinterpret_bits(value); const uint64_t E = bits >> (kPrecision - 1); @@ -8891,7 +8883,10 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, // = ((p1 ) * 2^-e + (p2 )) * 2^e // = p1 + p2 * 2^e - const diyfp one(uint64_t{1} << -M_plus.e, M_plus.e); + const diyfp one(uint64_t + { + 1 + } << -M_plus.e, M_plus.e); uint32_t p1 = static_cast(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e @@ -9753,9 +9748,9 @@ class serializer case UTF8_REJECT: // decode found invalid UTF-8 byte { - std::stringstream ss; - ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast(byte); - JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str())); + std::string sn(3, '\0'); + snprintf(&sn[0], sn.size(), "%.2X", byte); + JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn)); } default: // decode found yet incomplete multi-byte code point @@ -9781,9 +9776,9 @@ class serializer else { // we finish reading, but do not accept: string was incomplete - std::stringstream ss; - ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast(static_cast(s.back())); - JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + ss.str())); + std::string sn(3, '\0'); + snprintf(&sn[0], sn.size(), "%.2X", static_cast(s.back())); + JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } } @@ -18411,7 +18406,7 @@ struct hash /// @note: do not remove the space after '<', /// see https://github.com/nlohmann/json/pull/679 template<> -struct less< ::nlohmann::detail::value_t> +struct less<::nlohmann::detail::value_t> { /*! @brief compare two value_t enum values diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 79ccf6810..0e1a4874c 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -1093,9 +1093,9 @@ TEST_CASE("value conversion") SECTION("superfluous entries") { - json j8 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}}; - m2 = j8.get>(); - CHECK(m == m2); + json j8 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}}; + m2 = j8.get>(); + CHECK(m == m2); } } diff --git a/test/src/unit-inspection.cpp b/test/src/unit-inspection.cpp index 4c03cf968..e50c7338e 100644 --- a/test/src/unit-inspection.cpp +++ b/test/src/unit-inspection.cpp @@ -317,8 +317,8 @@ TEST_CASE("object inspection") SECTION("round trips") { for (const auto& s : - {"3.141592653589793", "1000000000000000010E5" - }) + {"3.141592653589793", "1000000000000000010E5" + }) { json j1 = json::parse(s); std::string s1 = j1.dump(); diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index 2d49b3272..358d6bb93 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -45,19 +45,19 @@ void from_json(const json&, pod) noexcept; void from_json(const json&, pod_bis); static json j; -static_assert(noexcept(json{}), ""); +static_assert(noexcept(json {}), ""); static_assert(noexcept(nlohmann::to_json(j, 2)), ""); static_assert(noexcept(nlohmann::to_json(j, 2.5)), ""); static_assert(noexcept(nlohmann::to_json(j, true)), ""); -static_assert(noexcept(nlohmann::to_json(j, test{})), ""); -static_assert(noexcept(nlohmann::to_json(j, pod{})), ""); -static_assert(not noexcept(nlohmann::to_json(j, pod_bis{})), ""); +static_assert(noexcept(nlohmann::to_json(j, test {})), ""); +static_assert(noexcept(nlohmann::to_json(j, pod {})), ""); +static_assert(not noexcept(nlohmann::to_json(j, pod_bis {})), ""); static_assert(noexcept(json(2)), ""); -static_assert(noexcept(json(test{})), ""); -static_assert(noexcept(json(pod{})), ""); +static_assert(noexcept(json(test {})), ""); +static_assert(noexcept(json(pod {})), ""); static_assert(noexcept(j.get()), ""); static_assert(not noexcept(j.get()), ""); -static_assert(noexcept(json(pod{})), ""); +static_assert(noexcept(json(pod {})), ""); TEST_CASE("runtime checks") { diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index 040c3e980..3807d212f 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -585,7 +585,7 @@ struct pod_serializer std::is_pod::value and std::is_class::value, int>::type = 0> static void to_json(BasicJsonType& j, const T& t) noexcept { - auto bytes = static_cast< const unsigned char*>(static_cast(&t)); + auto bytes = static_cast(static_cast(&t)); std::uint64_t value = bytes[0]; for (auto i = 1; i < 8; ++i) value |= std::uint64_t{bytes[i]} << 8 * i;