From 57e22b996e9b148fa9e727631442332df8562ce4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 13:08:10 +0100 Subject: [PATCH 01/15] :rotating_light: suppress warning --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 1d1e31f688..5a2e68e28a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -44,6 +44,7 @@ Checks: '*, -modernize-concat-nested-namespaces, -modernize-type-traits, -modernize-use-constraints, + -modernize-use-designated-initializers, -modernize-use-nodiscard, -modernize-use-std-numbers, -modernize-use-trailing-return-type, From b131d285ed919a21a0303815ced897993e230d1f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 17:27:37 +0100 Subject: [PATCH 02/15] :rotating_light: fix warning --- docs/examples/json_base_class_t.cpp | 4 +- .../nlohmann/detail/conversions/from_json.hpp | 2 +- .../detail/iterators/iteration_proxy.hpp | 2 +- .../detail/iterators/iterator_traits.hpp | 2 +- include/nlohmann/detail/meta/cpp_future.hpp | 2 +- include/nlohmann/detail/meta/type_traits.hpp | 30 +++++----- include/nlohmann/detail/output/serializer.hpp | 4 +- include/nlohmann/json.hpp | 2 +- include/nlohmann/ordered_map.hpp | 4 +- single_include/nlohmann/json.hpp | 58 +++++++++---------- tests/src/unit-bjdata.cpp | 14 ++--- tests/src/unit-cbor.cpp | 14 ++--- tests/src/unit-custom-base-class.cpp | 6 +- tests/src/unit-msgpack.cpp | 10 ++-- tests/src/unit-regression1.cpp | 16 ++--- 15 files changed, 85 insertions(+), 85 deletions(-) diff --git a/docs/examples/json_base_class_t.cpp b/docs/examples/json_base_class_t.cpp index d993522a70..3fb2d46a27 100644 --- a/docs/examples/json_base_class_t.cpp +++ b/docs/examples/json_base_class_t.cpp @@ -79,8 +79,8 @@ int main() // visit and output j.visit( - [&](const json::json_pointer & p, - const json & j) + [&](const json::json_pointer & p, + const json & j) { std::cout << (p.empty() ? std::string{"/"} : p.to_string()) << " - metadata = " << j.metadata << " -> " << j.dump() << '\n'; diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index aa2f0cbf4c..24cba8b751 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -275,7 +275,7 @@ void()) template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag> /*unused*/, index_sequence /*unused*/) + identity_tag> /*unused*/, index_sequence /*unused*/) { return { { std::forward(j).at(Idx).template get()... } }; } diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index 76293de227..aef19e3b3d 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -220,7 +220,7 @@ namespace std #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant {}; + : public std::integral_constant {}; template class tuple_element> // NOLINT(cert-dcl58-cpp) diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index 84cc27a85e..94870ecfa3 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp @@ -43,7 +43,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; diff --git a/include/nlohmann/detail/meta/cpp_future.hpp b/include/nlohmann/detail/meta/cpp_future.hpp index 412b5aa74b..cc0788059c 100644 --- a/include/nlohmann/detail/meta/cpp_future.hpp +++ b/include/nlohmann/detail/meta/cpp_future.hpp @@ -162,7 +162,7 @@ struct static_const #endif template -inline constexpr std::array make_array(Args&& ... args) +constexpr std::array make_array(Args&& ... args) { return std::array {{static_cast(std::forward(args))...}}; } diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index e1b000dcc2..c142cd76ba 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -261,19 +261,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -471,8 +471,8 @@ is_detected::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value&& - is_complete_type < - detected_t>::value >> +is_complete_type < +detected_t>::value >> { using value_type = range_value_t; @@ -595,12 +595,12 @@ using is_usable_as_key_type = typename std::conditional < template> using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type::value - && !is_json_iterator_of::value, - std::true_type, - std::false_type >::type; + is_usable_as_key_type::value + && !is_json_iterator_of::value, + std::true_type, + std::false_type >::type; template using detect_erase_with_key_type = decltype(std::declval().erase(std::declval())); @@ -734,7 +734,7 @@ struct value_in_range_of_impl1 }; template -inline constexpr bool value_in_range_of(T val) +constexpr bool value_in_range_of(T val) { return value_in_range_of_impl1::test(val); } @@ -750,7 +750,7 @@ namespace impl { template -inline constexpr bool is_c_string() +constexpr bool is_c_string() { using TUnExt = typename std::remove_extent::type; using TUnCVExt = typename std::remove_cv::type; @@ -778,7 +778,7 @@ namespace impl { template -inline constexpr bool is_transparent() +constexpr bool is_transparent() { return is_detected::value; } diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index ed20b0d9e1..1f179f8849 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -643,7 +643,7 @@ class serializer @param[in] x unsigned integer number to count its digits @return number of decimal digits */ - inline unsigned int count_digits(number_unsigned_t x) noexcept + unsigned int count_digits(number_unsigned_t x) noexcept { unsigned int n_digits = 1; for (;;) @@ -952,7 +952,7 @@ class serializer * absolute values of INT_MIN and INT_MAX are usually not the same. See * #1708 for details. */ - inline number_unsigned_t remove_sign(number_integer_t x) noexcept + number_unsigned_t remove_sign(number_integer_t x) noexcept { JSON_ASSERT(x < 0 && x < (std::numeric_limits::max)()); // NOLINT(misc-redundant-expression) return static_cast(-(x + 1)) + 1; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 31ca64539b..085a8336f5 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -137,7 +137,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), allow_exceptions, ignore_comments); } private: diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 39e4a50a14..ee6f8aeb1a 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -26,7 +26,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN /// for use within nlohmann::basic_json template , class Allocator = std::allocator>> - struct ordered_map : std::vector, Allocator> + struct ordered_map : std::vector, Allocator> { using key_type = Key; using mapped_type = T; @@ -341,7 +341,7 @@ template , template using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template> void insert(InputIt first, InputIt last) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a858728c4c..b3c08682d4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3219,7 +3219,7 @@ struct static_const #endif template -inline constexpr std::array make_array(Args&& ... args) +constexpr std::array make_array(Args&& ... args) { return std::array {{static_cast(std::forward(args))...}}; } @@ -3293,7 +3293,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; @@ -3674,19 +3674,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -3884,8 +3884,8 @@ is_detected::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value&& - is_complete_type < - detected_t>::value >> +is_complete_type < +detected_t>::value >> { using value_type = range_value_t; @@ -4008,12 +4008,12 @@ using is_usable_as_key_type = typename std::conditional < template> using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type::value - && !is_json_iterator_of::value, - std::true_type, - std::false_type >::type; + is_usable_as_key_type::value + && !is_json_iterator_of::value, + std::true_type, + std::false_type >::type; template using detect_erase_with_key_type = decltype(std::declval().erase(std::declval())); @@ -4147,7 +4147,7 @@ struct value_in_range_of_impl1 }; template -inline constexpr bool value_in_range_of(T val) +constexpr bool value_in_range_of(T val) { return value_in_range_of_impl1::test(val); } @@ -4163,7 +4163,7 @@ namespace impl { template -inline constexpr bool is_c_string() +constexpr bool is_c_string() { using TUnExt = typename std::remove_extent::type; using TUnCVExt = typename std::remove_cv::type; @@ -4191,7 +4191,7 @@ namespace impl { template -inline constexpr bool is_transparent() +constexpr bool is_transparent() { return is_detected::value; } @@ -4902,7 +4902,7 @@ void()) template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag> /*unused*/, index_sequence /*unused*/) + identity_tag> /*unused*/, index_sequence /*unused*/) { return { { std::forward(j).at(Idx).template get()... } }; } @@ -5369,7 +5369,7 @@ namespace std #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant {}; + : public std::integral_constant {}; template class tuple_element> // NOLINT(cert-dcl58-cpp) @@ -18652,7 +18652,7 @@ class serializer @param[in] x unsigned integer number to count its digits @return number of decimal digits */ - inline unsigned int count_digits(number_unsigned_t x) noexcept + unsigned int count_digits(number_unsigned_t x) noexcept { unsigned int n_digits = 1; for (;;) @@ -18961,7 +18961,7 @@ class serializer * absolute values of INT_MIN and INT_MAX are usually not the same. See * #1708 for details. */ - inline number_unsigned_t remove_sign(number_integer_t x) noexcept + number_unsigned_t remove_sign(number_integer_t x) noexcept { JSON_ASSERT(x < 0 && x < (std::numeric_limits::max)()); // NOLINT(misc-redundant-expression) return static_cast(-(x + 1)) + 1; @@ -19031,7 +19031,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN /// for use within nlohmann::basic_json template , class Allocator = std::allocator>> - struct ordered_map : std::vector, Allocator> + struct ordered_map : std::vector, Allocator> { using key_type = Key; using mapped_type = T; @@ -19346,7 +19346,7 @@ template , template using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template> void insert(InputIt first, InputIt last) @@ -19440,7 +19440,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), allow_exceptions, ignore_comments); } private: @@ -20136,8 +20136,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::enable_if_t < !detail::is_basic_json::value && detail::is_compatible_type::value, int > = 0 > basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) - JSONSerializer::to_json(std::declval(), - std::forward(val)))) + JSONSerializer::to_json(std::declval(), + std::forward(val)))) { JSONSerializer::to_json(*this, std::forward(val)); set_parents(); @@ -20907,7 +20907,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( - JSONSerializer::from_json(std::declval(), std::declval()))) + JSONSerializer::from_json(std::declval(), std::declval()))) { auto ret = ValueType(); JSONSerializer::from_json(*this, ret); @@ -20949,7 +20949,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_non_default_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( - JSONSerializer::from_json(std::declval()))) + JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); } @@ -21099,7 +21099,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_from_json::value, int > = 0 > ValueType & get_to(ValueType& v) const noexcept(noexcept( - JSONSerializer::from_json(std::declval(), v))) + JSONSerializer::from_json(std::declval(), v))) { JSONSerializer::from_json(*this, v); return v; diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 9f247fe6fe..7fdfd547de 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -339,13 +339,13 @@ TEST_CASE("BJData") std::vector const numbers { -32769, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index be94d2f6e1..332386471d 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -241,13 +241,13 @@ TEST_CASE("CBOR") const std::vector numbers { -65537, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -4294967296, - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index 7d3c2eefc4..6926de84aa 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp @@ -283,8 +283,8 @@ TEST_CASE("JSON Visit Node") }; json.visit( - [&](const json_with_visitor_t::json_pointer & p, - const json_with_visitor_t& j) + [&](const json_with_visitor_t::json_pointer & p, + const json_with_visitor_t& j) { std::stringstream str; str << p.to_string() << " - " ; @@ -331,6 +331,6 @@ TEST_CASE("JSON Visit Node") CHECK(expected.count(str.str()) == 1); expected.erase(str.str()); } - ); + ); CHECK(expected.empty()); } diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 61162afaec..e598adc687 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -479,11 +479,11 @@ TEST_CASE("MessagePack") std::vector const numbers { -32769, - -65536, - -77777, - -1048576, - -2147483648LL, - }; + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index f5ef5d80bf..44f208442c 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1328,10 +1328,10 @@ TEST_CASE("regression tests 1") { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() + | std::ios_base::failbit + | std::ios_base::badbit + ); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/regression/working_file.json"); json _; @@ -1341,10 +1341,10 @@ TEST_CASE("regression tests 1") { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() + | std::ios_base::failbit + | std::ios_base::badbit + ); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor", std::ios_base::in | std::ios_base::binary); From 7b89d3ab29b2fbbbfc7db273f08be7b3304795f3 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 17:32:27 +0100 Subject: [PATCH 03/15] :rotating_light: fix warning --- docs/examples/json_base_class_t.cpp | 4 +- .../nlohmann/detail/conversions/from_json.hpp | 2 +- .../detail/iterators/iteration_proxy.hpp | 2 +- .../detail/iterators/iterator_traits.hpp | 2 +- include/nlohmann/detail/meta/type_traits.hpp | 24 +++++----- include/nlohmann/json.hpp | 2 +- include/nlohmann/ordered_map.hpp | 4 +- single_include/nlohmann/json.hpp | 46 +++++++++---------- tests/src/unit-bjdata.cpp | 14 +++--- tests/src/unit-cbor.cpp | 14 +++--- tests/src/unit-custom-base-class.cpp | 6 +-- tests/src/unit-msgpack.cpp | 10 ++-- tests/src/unit-regression1.cpp | 16 +++---- 13 files changed, 73 insertions(+), 73 deletions(-) diff --git a/docs/examples/json_base_class_t.cpp b/docs/examples/json_base_class_t.cpp index 3fb2d46a27..d993522a70 100644 --- a/docs/examples/json_base_class_t.cpp +++ b/docs/examples/json_base_class_t.cpp @@ -79,8 +79,8 @@ int main() // visit and output j.visit( - [&](const json::json_pointer & p, - const json & j) + [&](const json::json_pointer & p, + const json & j) { std::cout << (p.empty() ? std::string{"/"} : p.to_string()) << " - metadata = " << j.metadata << " -> " << j.dump() << '\n'; diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 24cba8b751..aa2f0cbf4c 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -275,7 +275,7 @@ void()) template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag> /*unused*/, index_sequence /*unused*/) + identity_tag> /*unused*/, index_sequence /*unused*/) { return { { std::forward(j).at(Idx).template get()... } }; } diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index aef19e3b3d..76293de227 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -220,7 +220,7 @@ namespace std #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant {}; + : public std::integral_constant {}; template class tuple_element> // NOLINT(cert-dcl58-cpp) diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index 94870ecfa3..84cc27a85e 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp @@ -43,7 +43,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index c142cd76ba..4a7b3105b8 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -261,19 +261,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -471,8 +471,8 @@ is_detected::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value&& -is_complete_type < -detected_t>::value >> + is_complete_type < + detected_t>::value >> { using value_type = range_value_t; @@ -595,12 +595,12 @@ using is_usable_as_key_type = typename std::conditional < template> using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type::value - && !is_json_iterator_of::value, - std::true_type, - std::false_type >::type; + is_usable_as_key_type::value + && !is_json_iterator_of::value, + std::true_type, + std::false_type >::type; template using detect_erase_with_key_type = decltype(std::declval().erase(std::declval())); diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 085a8336f5..31ca64539b 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -137,7 +137,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), allow_exceptions, ignore_comments); } private: diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index ee6f8aeb1a..39e4a50a14 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -26,7 +26,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN /// for use within nlohmann::basic_json template , class Allocator = std::allocator>> - struct ordered_map : std::vector, Allocator> + struct ordered_map : std::vector, Allocator> { using key_type = Key; using mapped_type = T; @@ -341,7 +341,7 @@ template , template using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template> void insert(InputIt first, InputIt last) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b3c08682d4..82138b02f5 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3293,7 +3293,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; @@ -3674,19 +3674,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -3884,8 +3884,8 @@ is_detected::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value&& -is_complete_type < -detected_t>::value >> + is_complete_type < + detected_t>::value >> { using value_type = range_value_t; @@ -4008,12 +4008,12 @@ using is_usable_as_key_type = typename std::conditional < template> using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type::value - && !is_json_iterator_of::value, - std::true_type, - std::false_type >::type; + is_usable_as_key_type::value + && !is_json_iterator_of::value, + std::true_type, + std::false_type >::type; template using detect_erase_with_key_type = decltype(std::declval().erase(std::declval())); @@ -4902,7 +4902,7 @@ void()) template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag> /*unused*/, index_sequence /*unused*/) + identity_tag> /*unused*/, index_sequence /*unused*/) { return { { std::forward(j).at(Idx).template get()... } }; } @@ -5369,7 +5369,7 @@ namespace std #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant {}; + : public std::integral_constant {}; template class tuple_element> // NOLINT(cert-dcl58-cpp) @@ -19031,7 +19031,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN /// for use within nlohmann::basic_json template , class Allocator = std::allocator>> - struct ordered_map : std::vector, Allocator> + struct ordered_map : std::vector, Allocator> { using key_type = Key; using mapped_type = T; @@ -19346,7 +19346,7 @@ template , template using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template> void insert(InputIt first, InputIt last) @@ -19440,7 +19440,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), allow_exceptions, ignore_comments); } private: @@ -20136,8 +20136,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::enable_if_t < !detail::is_basic_json::value && detail::is_compatible_type::value, int > = 0 > basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) - JSONSerializer::to_json(std::declval(), - std::forward(val)))) + JSONSerializer::to_json(std::declval(), + std::forward(val)))) { JSONSerializer::to_json(*this, std::forward(val)); set_parents(); @@ -20907,7 +20907,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( - JSONSerializer::from_json(std::declval(), std::declval()))) + JSONSerializer::from_json(std::declval(), std::declval()))) { auto ret = ValueType(); JSONSerializer::from_json(*this, ret); @@ -20949,7 +20949,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_non_default_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( - JSONSerializer::from_json(std::declval()))) + JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); } @@ -21099,7 +21099,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::has_from_json::value, int > = 0 > ValueType & get_to(ValueType& v) const noexcept(noexcept( - JSONSerializer::from_json(std::declval(), v))) + JSONSerializer::from_json(std::declval(), v))) { JSONSerializer::from_json(*this, v); return v; diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 7fdfd547de..9f247fe6fe 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -339,13 +339,13 @@ TEST_CASE("BJData") std::vector const numbers { -32769, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 332386471d..be94d2f6e1 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -241,13 +241,13 @@ TEST_CASE("CBOR") const std::vector numbers { -65537, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -4294967296, - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index 6926de84aa..7d3c2eefc4 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp @@ -283,8 +283,8 @@ TEST_CASE("JSON Visit Node") }; json.visit( - [&](const json_with_visitor_t::json_pointer & p, - const json_with_visitor_t& j) + [&](const json_with_visitor_t::json_pointer & p, + const json_with_visitor_t& j) { std::stringstream str; str << p.to_string() << " - " ; @@ -331,6 +331,6 @@ TEST_CASE("JSON Visit Node") CHECK(expected.count(str.str()) == 1); expected.erase(str.str()); } - ); + ); CHECK(expected.empty()); } diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index e598adc687..61162afaec 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -479,11 +479,11 @@ TEST_CASE("MessagePack") std::vector const numbers { -32769, - -65536, - -77777, - -1048576, - -2147483648LL, - }; + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 44f208442c..f5ef5d80bf 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1328,10 +1328,10 @@ TEST_CASE("regression tests 1") { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() + | std::ios_base::failbit + | std::ios_base::badbit + ); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/regression/working_file.json"); json _; @@ -1341,10 +1341,10 @@ TEST_CASE("regression tests 1") { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() + | std::ios_base::failbit + | std::ios_base::badbit + ); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor", std::ios_base::in | std::ios_base::binary); From cc4d7f1697ad465889fa90284c66a7f5e42ed1fc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 18:33:24 +0100 Subject: [PATCH 04/15] :rotating_light: fix warning --- include/nlohmann/json.hpp | 6 ++---- single_include/nlohmann/json.hpp | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 31ca64539b..f4d582f504 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1213,11 +1213,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept : json_base_class_t(std::forward(other)), - m_data(std::move(other.m_data)) + // check that passed value is valid (has to be done before moving) + m_data(std::move((other.assert_invariant(false), other.m_data))) { - // check that passed value is valid - other.assert_invariant(false); - // invalidate payload other.m_data.m_type = value_t::null; other.m_data.m_value = {}; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 82138b02f5..546ea18d29 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20516,11 +20516,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept : json_base_class_t(std::forward(other)), - m_data(std::move(other.m_data)) + // check that passed value is valid (has to be done before moving) + m_data(std::move((other.assert_invariant(false), other.m_data))) { - // check that passed value is valid - other.assert_invariant(false); - // invalidate payload other.m_data.m_type = value_t::null; other.m_data.m_value = {}; From 22d3ee930eace3d89300a70b42ec3c9f112c8c0e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 18:57:27 +0100 Subject: [PATCH 05/15] :rotating_light: fix warning --- include/nlohmann/json.hpp | 6 +++--- single_include/nlohmann/json.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f4d582f504..b25e130b8c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1212,9 +1212,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief move constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept - : json_base_class_t(std::forward(other)), - // check that passed value is valid (has to be done before moving) - m_data(std::move((other.assert_invariant(false), other.m_data))) + // check that passed value is valid (has to be done before forwarding) + : json_base_class_t((other.assert_invariant(false), std::forward(other))), + m_data(std::move(other.m_data)) { // invalidate payload other.m_data.m_type = value_t::null; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 546ea18d29..77183af12b 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20515,9 +20515,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief move constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept - : json_base_class_t(std::forward(other)), - // check that passed value is valid (has to be done before moving) - m_data(std::move((other.assert_invariant(false), other.m_data))) + // check that passed value is valid (has to be done before forwarding) + : json_base_class_t((other.assert_invariant(false), std::forward(other))), + m_data(std::move(other.m_data)) { // invalidate payload other.m_data.m_type = value_t::null; From 91be9e017513b346af3d0a71615653f01ba1df4e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Mar 2024 19:24:59 +0100 Subject: [PATCH 06/15] :rotating_light: fix warning --- include/nlohmann/json.hpp | 6 +++--- single_include/nlohmann/json.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index b25e130b8c..8e8f81da45 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1214,11 +1214,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec basic_json(basic_json&& other) noexcept // check that passed value is valid (has to be done before forwarding) : json_base_class_t((other.assert_invariant(false), std::forward(other))), - m_data(std::move(other.m_data)) + m_data(std::move(other.m_data))// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) { // invalidate payload - other.m_data.m_type = value_t::null; - other.m_data.m_value = {}; + other.m_data.m_type = value_t::null; // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) + other.m_data.m_value = {};// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) set_parents(); assert_invariant(); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 77183af12b..d68584f97d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20517,11 +20517,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec basic_json(basic_json&& other) noexcept // check that passed value is valid (has to be done before forwarding) : json_base_class_t((other.assert_invariant(false), std::forward(other))), - m_data(std::move(other.m_data)) + m_data(std::move(other.m_data))// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) { // invalidate payload - other.m_data.m_type = value_t::null; - other.m_data.m_value = {}; + other.m_data.m_type = value_t::null; // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) + other.m_data.m_value = {};// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) set_parents(); assert_invariant(); From 8ef27594d14b77ef85869cb48d5a67fdbdc0c8fd Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 26 Mar 2024 17:25:26 +0100 Subject: [PATCH 07/15] :rotating_light: fix warning --- tests/src/unit-conversions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index d7df0bee55..1d89ec5447 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1164,7 +1164,7 @@ TEST_CASE("value conversion") SECTION("non-const") { - const json j_const = j; + const json j_const = j; // NOLINT(performance-unnecessary-copy-initialization) const auto& b = j_const.get_binary(); CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary); } From 414345eef98eb9b261da56b47a53745c55417e6a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 13 Apr 2024 14:59:13 +0200 Subject: [PATCH 08/15] :rotating_light: fix warning --- include/nlohmann/detail/conversions/from_json.hpp | 9 ++++++++- single_include/nlohmann/json.hpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index aa2f0cbf4c..41146cd21a 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -277,7 +277,14 @@ template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, identity_tag> /*unused*/, index_sequence /*unused*/) { - return { { std::forward(j).at(Idx).template get()... } }; + return { { j.at(Idx).template get < T&& > ()... } }; +} + +template < typename BasicJsonType, typename T, std::size_t... Idx > +std::array from_json_inplace_array_impl(const BasicJsonType& j, + identity_tag> /*unused*/, index_sequence /*unused*/) +{ + return { { j.at(Idx).template get()... } }; } template < typename BasicJsonType, typename T, std::size_t N > diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d68584f97d..2db129e563 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4904,7 +4904,14 @@ template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, identity_tag> /*unused*/, index_sequence /*unused*/) { - return { { std::forward(j).at(Idx).template get()... } }; + return { { j.at(Idx).template get < T&& > ()... } }; +} + +template < typename BasicJsonType, typename T, std::size_t... Idx > +std::array from_json_inplace_array_impl(const BasicJsonType& j, + identity_tag> /*unused*/, index_sequence /*unused*/) +{ + return { { j.at(Idx).template get()... } }; } template < typename BasicJsonType, typename T, std::size_t N > From 760f54f993341b1b5bd02c8f3f875aa908b4ebca Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 14 Apr 2024 12:01:20 +0200 Subject: [PATCH 09/15] :rotating_light: fix warning --- include/nlohmann/detail/conversions/from_json.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 41146cd21a..84b55f229e 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -277,7 +277,7 @@ template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, identity_tag> /*unused*/, index_sequence /*unused*/) { - return { { j.at(Idx).template get < T&& > ()... } }; + return { { std::forward(j).at(Idx).template get < T&& > ()... } }; } template < typename BasicJsonType, typename T, std::size_t... Idx > diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2db129e563..d88467d859 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4904,7 +4904,7 @@ template < typename BasicJsonType, typename T, std::size_t... Idx > std::array from_json_inplace_array_impl(BasicJsonType&& j, identity_tag> /*unused*/, index_sequence /*unused*/) { - return { { j.at(Idx).template get < T&& > ()... } }; + return { { std::forward(j).at(Idx).template get < T&& > ()... } }; } template < typename BasicJsonType, typename T, std::size_t... Idx > From e8cfe1f712296d0b0b9a4ba83aa69b8fea7364b8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 14 Apr 2024 12:38:17 +0200 Subject: [PATCH 10/15] :rotating_light: fix warning --- include/nlohmann/detail/conversions/from_json.hpp | 6 ++++++ single_include/nlohmann/json.hpp | 6 ++++++ tests/src/unit-conversions.cpp | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 84b55f229e..5663016169 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -380,6 +380,12 @@ inline void from_json(const BasicJsonType& j, ArithmeticType& val) } } +template +std::tuple from_json_tuple_impl_base(const BasicJsonType& j, index_sequence /*unused*/) +{ + return std::make_tuple(j.at(Idx).template get()...); +} + template std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence /*unused*/) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d88467d859..5703f0d5a9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5007,6 +5007,12 @@ inline void from_json(const BasicJsonType& j, ArithmeticType& val) } } +template +std::tuple from_json_tuple_impl_base(const BasicJsonType& j, index_sequence /*unused*/) +{ + return std::make_tuple(j.at(Idx).template get()...); +} + template std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence /*unused*/) { diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index 1d89ec5447..8692ada6d1 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1515,9 +1515,9 @@ NLOHMANN_JSON_SERIALIZE_ENUM(cards, enum TaskState { - TS_STOPPED, - TS_RUNNING, - TS_COMPLETED, + TS_STOPPED = 0, + TS_RUNNING = 1, + TS_COMPLETED = 2, TS_INVALID = -1, }; From 4b7721c392eb3241865893da5286caebea187c5f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 14 Apr 2024 13:56:22 +0200 Subject: [PATCH 11/15] :rotating_light: fix warning --- include/nlohmann/detail/conversions/from_json.hpp | 10 ++++++++-- single_include/nlohmann/json.hpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 5663016169..530f3a091b 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -395,8 +395,14 @@ std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence< template < typename BasicJsonType, class A1, class A2 > std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) { - return {std::forward(j).at(0).template get(), - std::forward(j).at(1).template get()}; + return {std::forward(j).at(0).template get < A1&& > (), + std::forward(j).at(1).template get < A2&& > ()}; +} + +template < typename BasicJsonType, class A1, class A2 > +std::pair from_json_tuple_impl(const BasicJsonType& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) +{ + return {j.at(0).template get(), j.at(1).template get()}; } template diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 5703f0d5a9..a3203d8f93 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5022,8 +5022,14 @@ std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence< template < typename BasicJsonType, class A1, class A2 > std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) { - return {std::forward(j).at(0).template get(), - std::forward(j).at(1).template get()}; + return {std::forward(j).at(0).template get < A1&& > (), + std::forward(j).at(1).template get < A2&& > ()}; +} + +template < typename BasicJsonType, class A1, class A2 > +std::pair from_json_tuple_impl(const BasicJsonType& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) +{ + return {j.at(0).template get(), j.at(1).template get()}; } template From bb2468a52ca9747bf720bbbc33a7ce6bf6e32bfc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 21:16:40 +0200 Subject: [PATCH 12/15] :rotating_light: fix warning --- include/nlohmann/json.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- tests/src/unit-diagnostics.cpp | 2 +- tests/src/unit-element_access2.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 8e8f81da45..dcfd0a8705 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2010,7 +2010,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = m_data.m_value.object->find(std::forward(key)); if (it == m_data.m_value.object->end()) { - JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward(key)), "' not found"), this)); + JSON_THROW(out_of_range::create(403, "key not found (key is an rvalue and cannot be shown)", this)); } return set_parent(it->second); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a3203d8f93..65c9e841a5 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21332,7 +21332,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = m_data.m_value.object->find(std::forward(key)); if (it == m_data.m_value.object->end()) { - JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward(key)), "' not found"), this)); + JSON_THROW(out_of_range::create(403, "key not found (key is an rvalue and cannot be shown)", this)); } return set_parent(it->second); } diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 0e172b915e..483f96e739 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -39,7 +39,7 @@ TEST_CASE("Better diagnostics") { json j; j["object"]["object"] = true; - CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range); + CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key not found (key is an rvalue and cannot be shown)", json::out_of_range); } SECTION("array index out of range") diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 8497fb944c..622d51c523 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -69,11 +69,11 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j SECTION("access outside bounds") { - CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); #ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); #endif } From 751b93652ff64421670310049e16d40549557d77 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 21:44:33 +0200 Subject: [PATCH 13/15] :rotating_light: fix warning --- include/nlohmann/json.hpp | 2 +- tests/src/unit-element_access2.cpp | 4 ++-- tests/src/unit-udt_macro.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index dcfd0a8705..ec208f916a 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2048,7 +2048,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = m_data.m_value.object->find(std::forward(key)); if (it == m_data.m_value.object->end()) { - JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward(key)), "' not found"), this)); + JSON_THROW(out_of_range::create(403, "key not found (key is an rvalue and cannot be shown)", this)); } return it->second; } diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 622d51c523..ae6ba955e9 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -70,11 +70,11 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j SECTION("access outside bounds") { CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); - CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); #ifdef JSON_HAS_CPP_17 CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); - CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); #endif } diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index 04631a4dc0..310fe068e5 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -341,7 +341,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); - CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); + CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", json::out_of_range); } } From 3c282210d6a40f281207516a9d2f1b951875c67e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 21:44:44 +0200 Subject: [PATCH 14/15] :rotating_light: fix warning --- single_include/nlohmann/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 65c9e841a5..1f28191630 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21370,7 +21370,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = m_data.m_value.object->find(std::forward(key)); if (it == m_data.m_value.object->end()) { - JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward(key)), "' not found"), this)); + JSON_THROW(out_of_range::create(403, "key not found (key is an rvalue and cannot be shown)", this)); } return it->second; } From fd968125e88ec5925c7ea741834ed9f6cae87bd9 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 22:50:47 +0200 Subject: [PATCH 15/15] :rotating_light: fix warning --- tests/src/unit-diagnostics.cpp | 5 +++++ tests/src/unit-element_access2.cpp | 5 +++++ tests/src/unit-udt_macro.cpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 483f96e739..c84a32fc8c 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -39,7 +39,12 @@ TEST_CASE("Better diagnostics") { json j; j["object"]["object"] = true; + +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key not found (key is an rvalue and cannot be shown)", json::out_of_range); +#else + CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range); +#endif } SECTION("array index out of range") diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index ae6ba955e9..0ef66bab7a 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -69,8 +69,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j SECTION("access outside bounds") { +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); +#else + CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); +#endif #ifdef JSON_HAS_CPP_17 CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index 310fe068e5..db51315528 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -341,7 +341,11 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", json::out_of_range); +#else + CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); +#endif } }