diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 3f69bcdf1..84d92c12f 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -230,7 +230,7 @@ class json_pointer const char* p = s.c_str(); char* p_end = nullptr; errno = 0; // strtoull doesn't reset errno - unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) if (p == p_end // invalid input or empty string || errno == ERANGE // out of range || JSON_HEDLEY_UNLIKELY(static_cast(p_end - p) != s.size())) // incomplete read diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 500fc55ec..a7dab5cd6 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -926,7 +926,7 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + const std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); JSON_ASSERT(index < 400); state = utf8d[index]; return state; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 442a31a7d..342fc0958 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13949,7 +13949,7 @@ class json_pointer const char* p = s.c_str(); char* p_end = nullptr; errno = 0; // strtoull doesn't reset errno - unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) if (p == p_end // invalid input or empty string || errno == ERANGE // out of range || JSON_HEDLEY_UNLIKELY(static_cast(p_end - p) != s.size())) // incomplete read @@ -18848,7 +18848,7 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + const std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); JSON_ASSERT(index < 400); state = utf8d[index]; return state; diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index c6b77ed66..76e3b03f1 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -159,7 +159,7 @@ TEST_CASE("controlled bad_alloc") SECTION("json_value(const string_t&)") { next_construct_fails = false; - my_json::string_t v("foo"); + const my_json::string_t v("foo"); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string)); next_construct_fails = true; CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc&); @@ -172,7 +172,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const CompatibleObjectType&)") { next_construct_fails = false; - std::map v {{"foo", "bar"}}; + const std::map v {{"foo", "bar"}}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -182,7 +182,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const CompatibleArrayType&)") { next_construct_fails = false; - std::vector v {"foo", "bar", "baz"}; + const std::vector v {"foo", "bar", "baz"}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -201,7 +201,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const typename string_t::value_type*)") { next_construct_fails = false; - std::string s("foo"); + const std::string s("foo"); CHECK_NOTHROW(my_json(s)); next_construct_fails = true; CHECK_THROWS_AS(my_json(s), std::bad_alloc&); diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 609b5d159..291c0ad5f 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -148,7 +148,7 @@ class alt_string alt_string substr(std::size_t pos = 0, std::size_t count = npos) const { - std::string s = str_impl.substr(pos, count); + const std::string s = str_impl.substr(pos, count); return {s.data(), s.size()}; }