diff --git a/.clang-tidy b/.clang-tidy index 11009409e8..4122a9ec19 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,6 +14,7 @@ Checks: '*, -fuchsia-overloaded-operator, -google-explicit-constructor, -google-readability-function-size, + -google-runtime-int, -google-runtime-references, -hicpp-avoid-goto, -hicpp-explicit-conversions, diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 7803d4b24e..faf1159f72 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -269,7 +269,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) } ConstructibleObjectType ret; - auto inner_object = j.template get_ptr(); + const auto* inner_object = j.template get_ptr(); using value_type = typename ConstructibleObjectType::value_type; std::transform( inner_object->begin(), inner_object->end(), diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index b45004fd42..bc201a088d 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -73,8 +73,7 @@ struct external_constructor static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) { j.m_type = value_t::binary; - typename BasicJsonType::binary_t value{b}; - j.m_value = value; + j.m_value = typename BasicJsonType::binary_t(b); j.assert_invariant(); } @@ -82,8 +81,7 @@ struct external_constructor static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) { j.m_type = value_t::binary; - typename BasicJsonType::binary_t value{std::move(b)}; - j.m_value = value; + j.m_value = typename BasicJsonType::binary_t(std::move(b));; j.assert_invariant(); } }; @@ -322,9 +320,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) template < typename BasicJsonType, typename T, std::size_t N, enable_if_t < !std::is_constructible::value, + const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) int > = 0 > -void to_json(BasicJsonType& j, const T(&arr)[N]) +void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { external_constructor::construct(j, arr); } diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index b89a77a6d4..4702a20fbb 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -399,7 +399,7 @@ class json_pointer */ BasicJsonType& get_and_create(BasicJsonType& j) const { - auto result = &j; + auto* result = &j; // in case no reference tokens exist, return a reference to the JSON value // j which will be overwritten by a primitive value diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index c784205913..2a945a98ad 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -36,7 +36,7 @@ class binary_writer @param[in] adapter output adapter to write to */ - explicit binary_writer(output_adapter_t adapter) : oa(adapter) + explicit binary_writer(output_adapter_t adapter) : oa(std::move(adapter)) { JSON_ASSERT(oa); } diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 3624d4b296..526941cc5d 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2937,7 +2937,7 @@ class basic_json static_assert(std::is_default_constructible::value, "types must be DefaultConstructible when used with get()"); - ValueType ret; + ValueType ret{}; JSONSerializer::from_json(*this, ret); return ret; } @@ -3044,10 +3044,10 @@ class basic_json template < typename T, std::size_t N, - typename Array = T (&)[N], + typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) detail::enable_if_t < detail::has_from_json::value, int > = 0 > - Array get_to(T (&v)[N]) const + Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) noexcept(noexcept(JSONSerializer::from_json( std::declval(), v))) { @@ -8753,7 +8753,7 @@ struct less<::nlohmann::detail::value_t> */ template<> inline void swap(nlohmann::json& j1, nlohmann::json& j2) noexcept( - is_nothrow_move_constructible::value&& + is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression) is_nothrow_move_assignable::value ) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index c932756302..ec128b0fcb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3751,7 +3751,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) } ConstructibleObjectType ret; - auto inner_object = j.template get_ptr(); + const auto* inner_object = j.template get_ptr(); using value_type = typename ConstructibleObjectType::value_type; std::transform( inner_object->begin(), inner_object->end(), @@ -4144,8 +4144,7 @@ struct external_constructor static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) { j.m_type = value_t::binary; - typename BasicJsonType::binary_t value{b}; - j.m_value = value; + j.m_value = typename BasicJsonType::binary_t(b); j.assert_invariant(); } @@ -4153,8 +4152,7 @@ struct external_constructor static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) { j.m_type = value_t::binary; - typename BasicJsonType::binary_t value{std::move(b)}; - j.m_value = value; + j.m_value = typename BasicJsonType::binary_t(std::move(b));; j.assert_invariant(); } }; @@ -4393,9 +4391,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) template < typename BasicJsonType, typename T, std::size_t N, enable_if_t < !std::is_constructible::value, + const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) int > = 0 > -void to_json(BasicJsonType& j, const T(&arr)[N]) +void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { external_constructor::construct(j, arr); } @@ -12055,7 +12053,7 @@ class json_pointer */ BasicJsonType& get_and_create(BasicJsonType& j) const { - auto result = &j; + auto* result = &j; // in case no reference tokens exist, return a reference to the JSON value // j which will be overwritten by a primitive value @@ -12877,7 +12875,7 @@ class binary_writer @param[in] adapter output adapter to write to */ - explicit binary_writer(output_adapter_t adapter) : oa(adapter) + explicit binary_writer(output_adapter_t adapter) : oa(std::move(adapter)) { JSON_ASSERT(oa); } @@ -19565,7 +19563,7 @@ class basic_json static_assert(std::is_default_constructible::value, "types must be DefaultConstructible when used with get()"); - ValueType ret; + ValueType ret{}; JSONSerializer::from_json(*this, ret); return ret; } @@ -19672,10 +19670,10 @@ class basic_json template < typename T, std::size_t N, - typename Array = T (&)[N], + typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) detail::enable_if_t < detail::has_from_json::value, int > = 0 > - Array get_to(T (&v)[N]) const + Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) noexcept(noexcept(JSONSerializer::from_json( std::declval(), v))) { @@ -25381,7 +25379,7 @@ struct less<::nlohmann::detail::value_t> */ template<> inline void swap(nlohmann::json& j1, nlohmann::json& j2) noexcept( - is_nothrow_move_constructible::value&& + is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression) is_nothrow_move_assignable::value ) { diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 4c8f311d43..f0baec98e8 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -2029,20 +2029,18 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) SECTION("input from flynn") { // most of these are excluded due to differences in key order (not a real problem) - auto exclude_packed = std::set - { - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json", - TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/regression/working_file.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", - }; + std::set exclude_packed; + exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor + exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json"); + exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json"); for (std::string filename : { diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index dde28c4b7b..87c2f9c46c 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -446,7 +446,7 @@ TEST_CASE("MessagePack") SECTION("-32768..-129 (int 16)") { - for (int16_t i = -32768; i <= -129; ++i) + for (int16_t i = -32768; i <= int16_t(-129); ++i) { CAPTURE(i) diff --git a/test/src/unit-regression1.cpp b/test/src/unit-regression1.cpp index c8a20a9cd7..ffbd184d03 100644 --- a/test/src/unit-regression1.cpp +++ b/test/src/unit-regression1.cpp @@ -115,7 +115,7 @@ using foo_json = nlohmann::basic_json