From ec95438a59dcbac5e078f61fa73471c7ab8787a3 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 6 Oct 2018 13:49:02 +0200 Subject: [PATCH 1/6] :rotating_light: fixed some linter warnings --- include/nlohmann/detail/conversions/to_json.hpp | 2 +- include/nlohmann/detail/input/lexer.hpp | 2 +- include/nlohmann/detail/json_pointer.hpp | 4 ++-- include/nlohmann/detail/output/serializer.hpp | 2 +- single_include/nlohmann/json.hpp | 10 +++++----- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index 0a80236988..b944bf6c9e 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -306,7 +306,7 @@ void to_json(BasicJsonType& j, const std::pair& p) // for https://github.com/nlohmann/json/pull/1134 template::iteration_proxy_internal>::value, int> = 0> -void to_json(BasicJsonType& j, T b) noexcept +void to_json(BasicJsonType& j, const T& b) { j = {{b.key(), b.value()}}; } diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 44165ff063..b4ff65fb0a 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -709,7 +709,7 @@ class lexer locale's decimal point is used instead of `.` to work with the locale-dependent converters. */ - token_type scan_number() + token_type scan_number() // lgtm [cpp/use-of-goto] { // reset token_buffer to store the number's bytes reset(); diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index fce8001a52..320730ecf3 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -506,11 +506,11 @@ class json_pointer std::size_t slash = reference_string.find_first_of('/', 1), // set the beginning of the first reference token start = 1; - // we can stop if start == string::npos+1 = 0 + // we can stop if start == 0 (if slash == std::string::npos) start != 0; // set the beginning of the next reference token // (will eventually be 0 if slash == std::string::npos) - start = slash + 1, + start = (slash == std::string::npos) ? 0 : slash + 1, // find next slash slash = reference_string.find_first_of('/', start)) { diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index e2655f049a..d4a258da0f 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -442,7 +442,7 @@ class serializer return; } - const bool is_negative = not (x >= 0); // see issue #755 + const bool is_negative = std::is_same::value and not (x >= 0); // see issue #755 std::size_t i = 0; while (x != 0) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index c40620ad63..d62638bd2c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -1839,7 +1839,7 @@ void to_json(BasicJsonType& j, const std::pair& p) // for https://github.com/nlohmann/json/pull/1134 template::iteration_proxy_internal>::value, int> = 0> -void to_json(BasicJsonType& j, T b) noexcept +void to_json(BasicJsonType& j, const T& b) { j = {{b.key(), b.value()}}; } @@ -2976,7 +2976,7 @@ class lexer locale's decimal point is used instead of `.` to work with the locale-dependent converters. */ - token_type scan_number() + token_type scan_number() // lgtm [cpp/use-of-goto] { // reset token_buffer to store the number's bytes reset(); @@ -10157,7 +10157,7 @@ class serializer return; } - const bool is_negative = not (x >= 0); // see issue #755 + const bool is_negative = std::is_same::value and not (x >= 0); // see issue #755 std::size_t i = 0; while (x != 0) @@ -10922,11 +10922,11 @@ class json_pointer std::size_t slash = reference_string.find_first_of('/', 1), // set the beginning of the first reference token start = 1; - // we can stop if start == string::npos+1 = 0 + // we can stop if start == 0 (if slash == std::string::npos) start != 0; // set the beginning of the next reference token // (will eventually be 0 if slash == std::string::npos) - start = slash + 1, + start = (slash == std::string::npos) ? 0 : slash + 1, // find next slash slash = reference_string.find_first_of('/', start)) { From fa722d5ac39d63a65db0b7383494997b7e3fc70e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 6 Oct 2018 16:26:47 +0200 Subject: [PATCH 2/6] :rotating_light: fixed another linter warning --- include/nlohmann/detail/input/binary_reader.hpp | 7 +++++-- single_include/nlohmann/json.hpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 05ab36f39c..6d72cbf04b 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -392,17 +392,20 @@ class binary_reader case 0xF9: // Half-Precision Float (two-byte IEEE 754) { - const int byte1 = get(); + const int byte1_raw = get(); if (JSON_UNLIKELY(not unexpect_eof())) { return false; } - const int byte2 = get(); + const int byte2_raw = get(); if (JSON_UNLIKELY(not unexpect_eof())) { return false; } + const unsigned char byte1 = static_cast(byte1_raw); + const unsigned char byte2 = static_cast(byte2_raw); + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d62638bd2c..a1a3d697fc 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6354,17 +6354,20 @@ class binary_reader case 0xF9: // Half-Precision Float (two-byte IEEE 754) { - const int byte1 = get(); + const int byte1_raw = get(); if (JSON_UNLIKELY(not unexpect_eof())) { return false; } - const int byte2 = get(); + const int byte2_raw = get(); if (JSON_UNLIKELY(not unexpect_eof())) { return false; } + const unsigned char byte1 = static_cast(byte1_raw); + const unsigned char byte2 = static_cast(byte2_raw); + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often From 858e75c4df6ea62973feb70d10af5c3531e37384 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 7 Oct 2018 18:39:18 +0200 Subject: [PATCH 3/6] :rotating_light: fixed some clang-tidy warnings --- include/nlohmann/adl_serializer.hpp | 2 +- .../nlohmann/detail/conversions/from_json.hpp | 8 +- .../nlohmann/detail/conversions/to_chars.hpp | 19 +- .../nlohmann/detail/conversions/to_json.hpp | 8 +- include/nlohmann/detail/exceptions.hpp | 4 +- .../nlohmann/detail/input/binary_reader.hpp | 10 +- .../nlohmann/detail/input/input_adapters.hpp | 15 +- include/nlohmann/detail/input/json_sax.hpp | 30 +-- include/nlohmann/detail/input/lexer.hpp | 19 +- include/nlohmann/detail/input/parser.hpp | 4 +- .../detail/iterators/internal_iterator.hpp | 4 +- .../nlohmann/detail/iterators/iter_impl.hpp | 4 +- .../detail/iterators/iteration_proxy.hpp | 7 +- .../iterators/json_reverse_iterator.hpp | 4 +- .../detail/iterators/primitive_iterator.hpp | 4 +- include/nlohmann/detail/json_pointer.hpp | 2 +- include/nlohmann/detail/json_ref.hpp | 8 +- include/nlohmann/detail/meta/cpp_future.hpp | 4 +- include/nlohmann/detail/meta/detected.hpp | 4 +- include/nlohmann/detail/meta/is_sax.hpp | 4 +- include/nlohmann/detail/meta/type_traits.hpp | 4 +- include/nlohmann/detail/meta/void_t.hpp | 4 +- .../nlohmann/detail/output/binary_writer.hpp | 18 +- .../detail/output/output_adapters.hpp | 4 +- include/nlohmann/detail/output/serializer.hpp | 7 +- include/nlohmann/detail/value_t.hpp | 4 +- include/nlohmann/json.hpp | 2 +- include/nlohmann/json_fwd.hpp | 2 +- single_include/nlohmann/json.hpp | 209 +++++++++--------- 29 files changed, 214 insertions(+), 204 deletions(-) diff --git a/include/nlohmann/adl_serializer.hpp b/include/nlohmann/adl_serializer.hpp index 0c28d1c73f..35be76fdc6 100644 --- a/include/nlohmann/adl_serializer.hpp +++ b/include/nlohmann/adl_serializer.hpp @@ -46,4 +46,4 @@ struct adl_serializer ::nlohmann::to_json(j, std::forward(val)); } }; -} +} // namespace nlohmann diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 2375d0660b..358b1c6588 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -299,7 +299,7 @@ void from_json(const BasicJsonType& j, std::pair& p) } template -void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence /*unused*/) { t = std::make_tuple(j.at(Idx).template get::type>()...); } @@ -358,7 +358,7 @@ struct from_json_fn return from_json(j, val); } }; -} +} // namespace detail /// namespace to hold default `from_json` function /// to see why this is required: @@ -366,5 +366,5 @@ struct from_json_fn namespace { constexpr const auto& from_json = detail::static_const::value; -} -} +} // namespace +} // namespace nlohmann diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index a13d258cb0..b32e176673 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -47,10 +47,9 @@ struct diyfp // f * 2^e { static constexpr int kPrecision = 64; // = q - uint64_t f; - int e; + uint64_t f = 0; + int e = 0; - constexpr diyfp() noexcept : f(0), e(0) {} constexpr diyfp(uint64_t f_, int e_) noexcept : f(f_), e(e_) {} /*! @@ -62,7 +61,7 @@ struct diyfp // f * 2^e assert(x.e == y.e); assert(x.f >= y.f); - return diyfp(x.f - y.f, x.e); + return {x.f - y.f, x.e}; } /*! @@ -127,7 +126,7 @@ struct diyfp // f * 2^e const uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32); - return diyfp(h, x.e + y.e + 64); + return {h, x.e + y.e + 64}; } /*! @@ -158,7 +157,7 @@ struct diyfp // f * 2^e assert(delta >= 0); assert(((x.f << delta) >> delta) == x.f); - return diyfp(x.f << delta, target_exponent); + return {x.f << delta, target_exponent}; } }; @@ -461,7 +460,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e) assert(e >= -1500); assert(e <= 1500); const int f = kAlpha - e - 1; - const int k = (f * 78913) / (1 << 18) + (f > 0); + const int k = (f * 78913) / (1 << 18) + static_cast(f > 0); const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep; assert(index >= 0); @@ -609,7 +608,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, 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.) + auto 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 // 1) @@ -928,7 +927,7 @@ inline char* append_exponent(char* buf, int e) *buf++ = '+'; } - uint32_t k = static_cast(e); + auto k = static_cast(e); if (k < 10) { // Always print at least two digits in the exponent. @@ -1046,7 +1045,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation. @note The result is NOT null-terminated. */ template -char* to_chars(char* first, char* last, FloatType value) +char* to_chars(char* first, const char* last, FloatType value) { static_cast(last); // maybe unused - fix warning assert(std::isfinite(value)); diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index b944bf6c9e..d274eadd53 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -312,7 +312,7 @@ void to_json(BasicJsonType& j, const T& b) } template -void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence) +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence /*unused*/) { j = {std::get(t)...}; } @@ -332,11 +332,11 @@ struct to_json_fn return to_json(j, std::forward(val)); } }; -} +} // namespace detail /// namespace to hold default `to_json` function namespace { constexpr const auto& to_json = detail::static_const::value; -} -} +} // namespace +} // namespace nlohmann diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index b73d7b1f94..d3d4c224d3 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -326,5 +326,5 @@ class other_error : public exception private: other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 6d72cbf04b..bb0c982b80 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -403,8 +403,8 @@ class binary_reader return false; } - const unsigned char byte1 = static_cast(byte1_raw); - const unsigned char byte2 = static_cast(byte2_raw); + const auto byte1 = static_cast(byte1_raw); + const auto byte2 = static_cast(byte2_raw); // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added @@ -1039,6 +1039,7 @@ class binary_reader } if (len != std::size_t(-1)) + { for (std::size_t i = 0; i < len; ++i) { if (JSON_UNLIKELY(not parse_cbor_internal())) @@ -1046,6 +1047,7 @@ class binary_reader return false; } } + } else { while (get() != 0xFF) @@ -1696,5 +1698,5 @@ class binary_reader /// the SAX parser json_sax_t* sax = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 1ae77b5efd..706c5c5b95 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -71,6 +71,8 @@ class input_stream_adapter : public input_adapter_protocol // delete because of pointer members input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete; + input_stream_adapter(input_stream_adapter&&) = delete; + input_stream_adapter& operator=(input_stream_adapter&&) = delete; // std::istream/std::streambuf use std::char_traits::to_int_type, to // ensure that std::char_traits::eof() and the character 0xFF do not @@ -97,6 +99,9 @@ class input_buffer_adapter : public input_adapter_protocol // delete because of pointer members input_buffer_adapter(const input_buffer_adapter&) = delete; input_buffer_adapter& operator=(input_buffer_adapter&) = delete; + input_buffer_adapter(input_buffer_adapter&&) = delete; + input_buffer_adapter& operator=(input_buffer_adapter&&) = delete; + ~input_buffer_adapter() override = default; std::char_traits::int_type get_character() noexcept override { @@ -131,7 +136,7 @@ struct wide_string_input_helper else { // get the current character - const int wc = static_cast(str[current_wchar++]); + const auto wc = static_cast(str[current_wchar++]); // UTF-32 to UTF-8 encoding if (wc < 0x80) @@ -186,7 +191,7 @@ struct wide_string_input_helper else { // get the current character - const int wc = static_cast(str[current_wchar++]); + const auto wc = static_cast(str[current_wchar++]); // UTF-16 to UTF-8 encoding if (wc < 0x80) @@ -211,7 +216,7 @@ struct wide_string_input_helper { if (current_wchar < str.size()) { - const int wc2 = static_cast(str[current_wchar++]); + const auto wc2 = static_cast(str[current_wchar++]); const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF)); utf8_bytes[0] = 0xf0 | (charcode >> 18); utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F); @@ -381,5 +386,5 @@ class input_adapter /// the actual adapter input_adapter_t ia = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 1705a86119..8cc18abc2a 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -181,7 +181,7 @@ class json_sax_dom_parser return true; } - bool number_float(number_float_t val, const string_t&) + bool number_float(number_float_t val, const string_t& /*unused*/) { handle_value(val); return true; @@ -238,7 +238,7 @@ class json_sax_dom_parser return true; } - bool parse_error(std::size_t, const std::string&, + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& ex) { errored = true; @@ -358,7 +358,7 @@ class json_sax_dom_callback_parser return true; } - bool number_float(number_float_t val, const string_t&) + bool number_float(number_float_t val, const string_t& /*unused*/) { handle_value(val); return true; @@ -496,7 +496,7 @@ class json_sax_dom_callback_parser return true; } - bool parse_error(std::size_t, const std::string&, + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& ex) { errored = true; @@ -642,37 +642,37 @@ class json_sax_acceptor return true; } - bool boolean(bool) + bool boolean(bool /*unused*/) { return true; } - bool number_integer(number_integer_t) + bool number_integer(number_integer_t /*unused*/) { return true; } - bool number_unsigned(number_unsigned_t) + bool number_unsigned(number_unsigned_t /*unused*/) { return true; } - bool number_float(number_float_t, const string_t&) + bool number_float(number_float_t /*unused*/, const string_t& /*unused*/) { return true; } - bool string(string_t&) + bool string(string_t& /*unused*/) { return true; } - bool start_object(std::size_t = std::size_t(-1)) + bool start_object(std::size_t /*unused*/ = std::size_t(-1)) { return true; } - bool key(string_t&) + bool key(string_t& /*unused*/) { return true; } @@ -682,7 +682,7 @@ class json_sax_acceptor return true; } - bool start_array(std::size_t = std::size_t(-1)) + bool start_array(std::size_t /*unused*/ = std::size_t(-1)) { return true; } @@ -692,11 +692,11 @@ class json_sax_acceptor return true; } - bool parse_error(std::size_t, const std::string&, const detail::exception&) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/) { return false; } }; -} +} // namespace detail -} +} // namespace nlohmann diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index b4ff65fb0a..4470e932f8 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -104,7 +104,10 @@ class lexer // delete because of pointer members lexer(const lexer&) = delete; + lexer(lexer&&) noexcept = default; lexer& operator=(lexer&) = delete; + lexer& operator=(lexer&&) noexcept = default; + ~lexer() = default; private: ///////////////////// @@ -1208,16 +1211,8 @@ class lexer { if (get() == 0xEF) { - if (get() == 0xBB and get() == 0xBF) - { - // we completely parsed the BOM - return true; - } - else - { - // after reading 0xEF, an unexpected character followed - return false; - } + // check if we completely parse the BOM + return get() == 0xBB and get() == 0xBF; } else { @@ -1329,5 +1324,5 @@ class lexer /// the decimal point const char decimal_point_char = '.'; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index 70d92a26e0..1ee1e6bf20 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -484,5 +484,5 @@ class parser /// whether to throw exceptions in case of errors const bool allow_exceptions = true; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/iterators/internal_iterator.hpp b/include/nlohmann/detail/iterators/internal_iterator.hpp index d9b8fb2947..2c81f723fd 100644 --- a/include/nlohmann/detail/iterators/internal_iterator.hpp +++ b/include/nlohmann/detail/iterators/internal_iterator.hpp @@ -21,5 +21,5 @@ template struct internal_iterator /// generic iterator for all other types primitive_iterator_t primitive_iterator {}; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/iterators/iter_impl.hpp b/include/nlohmann/detail/iterators/iter_impl.hpp index adcd8a37bb..6674c06450 100644 --- a/include/nlohmann/detail/iterators/iter_impl.hpp +++ b/include/nlohmann/detail/iterators/iter_impl.hpp @@ -610,5 +610,5 @@ class iter_impl /// the actual iterator of the associated instance internal_iterator::type> m_it; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index f5dbb2c73a..d4f905027d 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -39,9 +39,6 @@ template class iteration_proxy public: explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {} - iteration_proxy_internal(const iteration_proxy_internal&) = default; - iteration_proxy_internal& operator=(const iteration_proxy_internal&) = default; - /// dereference operator (needed for range-based for) iteration_proxy_internal& operator*() { @@ -124,5 +121,5 @@ template class iteration_proxy return iteration_proxy_internal(container.end()); } }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp index 2750de4ac8..f3b5b5db6b 100644 --- a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +++ b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp @@ -115,5 +115,5 @@ class json_reverse_iterator : public std::reverse_iterator return it.operator * (); } }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/iterators/primitive_iterator.hpp b/include/nlohmann/detail/iterators/primitive_iterator.hpp index db3f89757f..28d6f1a65d 100644 --- a/include/nlohmann/detail/iterators/primitive_iterator.hpp +++ b/include/nlohmann/detail/iterators/primitive_iterator.hpp @@ -116,5 +116,5 @@ class primitive_iterator_t return *this; } }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 320730ecf3..b2bc47277e 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -693,4 +693,4 @@ class json_pointer /// the reference tokens std::vector reference_tokens; }; -} +} // namespace nlohmann diff --git a/include/nlohmann/detail/json_ref.hpp b/include/nlohmann/detail/json_ref.hpp index 8285be22bb..b9abc47af1 100644 --- a/include/nlohmann/detail/json_ref.hpp +++ b/include/nlohmann/detail/json_ref.hpp @@ -31,9 +31,11 @@ class json_ref {} // class should be movable only - json_ref(json_ref&&) = default; + json_ref(json_ref&&) noexcept = default; json_ref(const json_ref&) = delete; json_ref& operator=(const json_ref&) = delete; + json_ref& operator=(json_ref&&) noexcept = default; + ~json_ref() = default; value_type moved_or_copied() const { @@ -59,5 +61,5 @@ class json_ref value_type* value_ref = nullptr; const bool is_rvalue; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/cpp_future.hpp b/include/nlohmann/detail/meta/cpp_future.hpp index fa7478b863..948cd4fb0c 100644 --- a/include/nlohmann/detail/meta/cpp_future.hpp +++ b/include/nlohmann/detail/meta/cpp_future.hpp @@ -59,5 +59,5 @@ struct static_const template constexpr T static_const::value; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/detected.hpp b/include/nlohmann/detail/meta/detected.hpp index ed1d6ac71d..c1bd547689 100644 --- a/include/nlohmann/detail/meta/detected.hpp +++ b/include/nlohmann/detail/meta/detected.hpp @@ -52,5 +52,5 @@ using is_detected_exact = std::is_same>; template class Op, class... Args> using is_detected_convertible = std::is_convertible, To>; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index b4e1f3fda1..b610beabf1 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp @@ -137,5 +137,5 @@ struct is_sax_static_asserts "Missing/invalid function: bool parse_error(std::size_t, const " "std::string&, const exception&)"); }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index bb932ef60c..1a1a174461 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -247,5 +247,5 @@ struct is_compatible_type_impl < template struct is_compatible_type : is_compatible_type_impl {}; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/void_t.hpp b/include/nlohmann/detail/meta/void_t.hpp index 2528ea84c2..a256f85ad1 100644 --- a/include/nlohmann/detail/meta/void_t.hpp +++ b/include/nlohmann/detail/meta/void_t.hpp @@ -9,5 +9,5 @@ template struct make_void using type = void; }; template using void_t = typename make_void::type; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 71e5ec81e4..17df41d831 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -540,9 +540,11 @@ class binary_writer case value_t::boolean: { if (add_prefix) + { oa->write_character(j.m_value.boolean ? static_cast('T') : static_cast('F')); + } break; } @@ -908,32 +910,32 @@ class binary_writer } } - static constexpr CharType get_cbor_float_prefix(float) + static constexpr CharType get_cbor_float_prefix(float /*unused*/) { return static_cast(0xFA); // Single-Precision Float } - static constexpr CharType get_cbor_float_prefix(double) + static constexpr CharType get_cbor_float_prefix(double /*unused*/) { return static_cast(0xFB); // Double-Precision Float } - static constexpr CharType get_msgpack_float_prefix(float) + static constexpr CharType get_msgpack_float_prefix(float /*unused*/) { return static_cast(0xCA); // float 32 } - static constexpr CharType get_msgpack_float_prefix(double) + static constexpr CharType get_msgpack_float_prefix(double /*unused*/) { return static_cast(0xCB); // float 64 } - static constexpr CharType get_ubjson_float_prefix(float) + static constexpr CharType get_ubjson_float_prefix(float /*unused*/) { return 'd'; // float 32 } - static constexpr CharType get_ubjson_float_prefix(double) + static constexpr CharType get_ubjson_float_prefix(double /*unused*/) { return 'D'; // float 64 } @@ -945,5 +947,5 @@ class binary_writer /// the output output_adapter_t oa = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp index ff86a6e19f..0a37715c28 100644 --- a/include/nlohmann/detail/output/output_adapters.hpp +++ b/include/nlohmann/detail/output/output_adapters.hpp @@ -109,5 +109,5 @@ class output_adapter private: output_adapter_t oa = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index d4a258da0f..6088ebe893 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -53,6 +53,9 @@ class serializer // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; + serializer(serializer&&) noexcept = default; + serializer& operator=(serializer&&) noexcept = default; + ~serializer() = default; /*! @brief internal implementation of the serialization function @@ -627,5 +630,5 @@ class serializer /// the indentation string string_t indent_string; }; -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/detail/value_t.hpp b/include/nlohmann/detail/value_t.hpp index 326367c428..10d555b997 100644 --- a/include/nlohmann/detail/value_t.hpp +++ b/include/nlohmann/detail/value_t.hpp @@ -72,5 +72,5 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept const auto r_index = static_cast(rhs); return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index]; } -} -} +} // namespace detail +} // namespace nlohmann diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 52c301cf7d..0b6a6fb5a1 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1866,7 +1866,7 @@ class basic_json @since version 1.0.0 */ - reference& operator=(basic_json other) noexcept ( + basic_json& operator=(basic_json other) noexcept ( std::is_nothrow_move_constructible::value and std::is_nothrow_move_assignable::value and std::is_nothrow_move_constructible::value and diff --git a/include/nlohmann/json_fwd.hpp b/include/nlohmann/json_fwd.hpp index 5ff0d75373..32abba9130 100644 --- a/include/nlohmann/json_fwd.hpp +++ b/include/nlohmann/json_fwd.hpp @@ -59,6 +59,6 @@ uses the standard template types. @since version 1.0.0 */ using json = basic_json<>; -} +} // namespace nlohmann #endif diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a1a3d697fc..210fc88c38 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -108,7 +108,7 @@ uses the standard template types. @since version 1.0.0 */ using json = basic_json<>; -} +} // namespace nlohmann #endif @@ -280,8 +280,8 @@ struct static_const template constexpr T static_const::value; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -312,8 +312,8 @@ template struct make_void using type = void; }; template using void_t = typename make_void::type; -} -} +} // namespace detail +} // namespace nlohmann // http://en.cppreference.com/w/cpp/experimental/is_detected @@ -364,8 +364,8 @@ using is_detected_exact = std::is_same>; template class Op, class... Args> using is_detected_convertible = std::is_convertible, To>; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -607,8 +607,8 @@ struct is_compatible_type_impl < template struct is_compatible_type : is_compatible_type_impl {}; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -939,8 +939,8 @@ class other_error : public exception private: other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -1017,8 +1017,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept const auto r_index = static_cast(rhs); return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index]; } -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -1327,7 +1327,7 @@ void from_json(const BasicJsonType& j, std::pair& p) } template -void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence /*unused*/) { t = std::make_tuple(j.at(Idx).template get::type>()...); } @@ -1386,7 +1386,7 @@ struct from_json_fn return from_json(j, val); } }; -} +} // namespace detail /// namespace to hold default `from_json` function /// to see why this is required: @@ -1394,8 +1394,8 @@ struct from_json_fn namespace { constexpr const auto& from_json = detail::static_const::value; -} -} +} // namespace +} // namespace nlohmann // #include @@ -1457,9 +1457,6 @@ template class iteration_proxy public: explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {} - iteration_proxy_internal(const iteration_proxy_internal&) = default; - iteration_proxy_internal& operator=(const iteration_proxy_internal&) = default; - /// dereference operator (needed for range-based for) iteration_proxy_internal& operator*() { @@ -1542,8 +1539,8 @@ template class iteration_proxy return iteration_proxy_internal(container.end()); } }; -} -} +} // namespace detail +} // namespace nlohmann namespace nlohmann @@ -1845,7 +1842,7 @@ void to_json(BasicJsonType& j, const T& b) } template -void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence) +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence /*unused*/) { j = {std::get(t)...}; } @@ -1865,14 +1862,14 @@ struct to_json_fn return to_json(j, std::forward(val)); } }; -} +} // namespace detail /// namespace to hold default `to_json` function namespace { constexpr const auto& to_json = detail::static_const::value; -} -} +} // namespace +} // namespace nlohmann // #include @@ -1949,6 +1946,8 @@ class input_stream_adapter : public input_adapter_protocol // delete because of pointer members input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete; + input_stream_adapter(input_stream_adapter&&) = delete; + input_stream_adapter& operator=(input_stream_adapter&&) = delete; // std::istream/std::streambuf use std::char_traits::to_int_type, to // ensure that std::char_traits::eof() and the character 0xFF do not @@ -1975,6 +1974,9 @@ class input_buffer_adapter : public input_adapter_protocol // delete because of pointer members input_buffer_adapter(const input_buffer_adapter&) = delete; input_buffer_adapter& operator=(input_buffer_adapter&) = delete; + input_buffer_adapter(input_buffer_adapter&&) = delete; + input_buffer_adapter& operator=(input_buffer_adapter&&) = delete; + ~input_buffer_adapter() override = default; std::char_traits::int_type get_character() noexcept override { @@ -2009,7 +2011,7 @@ struct wide_string_input_helper else { // get the current character - const int wc = static_cast(str[current_wchar++]); + const auto wc = static_cast(str[current_wchar++]); // UTF-32 to UTF-8 encoding if (wc < 0x80) @@ -2064,7 +2066,7 @@ struct wide_string_input_helper else { // get the current character - const int wc = static_cast(str[current_wchar++]); + const auto wc = static_cast(str[current_wchar++]); // UTF-16 to UTF-8 encoding if (wc < 0x80) @@ -2089,7 +2091,7 @@ struct wide_string_input_helper { if (current_wchar < str.size()) { - const int wc2 = static_cast(str[current_wchar++]); + const auto wc2 = static_cast(str[current_wchar++]); const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF)); utf8_bytes[0] = 0xf0 | (charcode >> 18); utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F); @@ -2259,8 +2261,8 @@ class input_adapter /// the actual adapter input_adapter_t ia = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -2371,7 +2373,10 @@ class lexer // delete because of pointer members lexer(const lexer&) = delete; + lexer(lexer&&) noexcept = default; lexer& operator=(lexer&) = delete; + lexer& operator=(lexer&&) noexcept = default; + ~lexer() = default; private: ///////////////////// @@ -3475,16 +3480,8 @@ class lexer { if (get() == 0xEF) { - if (get() == 0xBB and get() == 0xBF) - { - // we completely parsed the BOM - return true; - } - else - { - // after reading 0xEF, an unexpected character followed - return false; - } + // check if we completely parse the BOM + return get() == 0xBB and get() == 0xBF; } else { @@ -3596,8 +3593,8 @@ class lexer /// the decimal point const char decimal_point_char = '.'; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -3755,8 +3752,8 @@ struct is_sax_static_asserts "Missing/invalid function: bool parse_error(std::size_t, const " "std::string&, const exception&)"); }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -3946,7 +3943,7 @@ class json_sax_dom_parser return true; } - bool number_float(number_float_t val, const string_t&) + bool number_float(number_float_t val, const string_t& /*unused*/) { handle_value(val); return true; @@ -4003,7 +4000,7 @@ class json_sax_dom_parser return true; } - bool parse_error(std::size_t, const std::string&, + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& ex) { errored = true; @@ -4123,7 +4120,7 @@ class json_sax_dom_callback_parser return true; } - bool number_float(number_float_t val, const string_t&) + bool number_float(number_float_t val, const string_t& /*unused*/) { handle_value(val); return true; @@ -4261,7 +4258,7 @@ class json_sax_dom_callback_parser return true; } - bool parse_error(std::size_t, const std::string&, + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& ex) { errored = true; @@ -4407,37 +4404,37 @@ class json_sax_acceptor return true; } - bool boolean(bool) + bool boolean(bool /*unused*/) { return true; } - bool number_integer(number_integer_t) + bool number_integer(number_integer_t /*unused*/) { return true; } - bool number_unsigned(number_unsigned_t) + bool number_unsigned(number_unsigned_t /*unused*/) { return true; } - bool number_float(number_float_t, const string_t&) + bool number_float(number_float_t /*unused*/, const string_t& /*unused*/) { return true; } - bool string(string_t&) + bool string(string_t& /*unused*/) { return true; } - bool start_object(std::size_t = std::size_t(-1)) + bool start_object(std::size_t /*unused*/ = std::size_t(-1)) { return true; } - bool key(string_t&) + bool key(string_t& /*unused*/) { return true; } @@ -4447,7 +4444,7 @@ class json_sax_acceptor return true; } - bool start_array(std::size_t = std::size_t(-1)) + bool start_array(std::size_t /*unused*/ = std::size_t(-1)) { return true; } @@ -4457,14 +4454,14 @@ class json_sax_acceptor return true; } - bool parse_error(std::size_t, const std::string&, const detail::exception&) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/) { return false; } }; -} +} // namespace detail -} +} // namespace nlohmann // #include @@ -4940,8 +4937,8 @@ class parser /// whether to throw exceptions in case of errors const bool allow_exceptions = true; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -5062,8 +5059,8 @@ class primitive_iterator_t return *this; } }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -5090,8 +5087,8 @@ template struct internal_iterator /// generic iterator for all other types primitive_iterator_t primitive_iterator {}; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -5712,8 +5709,8 @@ class iter_impl /// the actual iterator of the associated instance internal_iterator::type> m_it; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -5835,8 +5832,8 @@ class json_reverse_iterator : public std::reverse_iterator return it.operator * (); } }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -5950,8 +5947,8 @@ class output_adapter private: output_adapter_t oa = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -6365,8 +6362,8 @@ class binary_reader return false; } - const unsigned char byte1 = static_cast(byte1_raw); - const unsigned char byte2 = static_cast(byte2_raw); + const auto byte1 = static_cast(byte1_raw); + const auto byte2 = static_cast(byte2_raw); // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added @@ -7001,6 +6998,7 @@ class binary_reader } if (len != std::size_t(-1)) + { for (std::size_t i = 0; i < len; ++i) { if (JSON_UNLIKELY(not parse_cbor_internal())) @@ -7008,6 +7006,7 @@ class binary_reader return false; } } + } else { while (get() != 0xFF) @@ -7658,8 +7657,8 @@ class binary_reader /// the SAX parser json_sax_t* sax = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -8206,9 +8205,11 @@ class binary_writer case value_t::boolean: { if (add_prefix) + { oa->write_character(j.m_value.boolean ? static_cast('T') : static_cast('F')); + } break; } @@ -8574,32 +8575,32 @@ class binary_writer } } - static constexpr CharType get_cbor_float_prefix(float) + static constexpr CharType get_cbor_float_prefix(float /*unused*/) { return static_cast(0xFA); // Single-Precision Float } - static constexpr CharType get_cbor_float_prefix(double) + static constexpr CharType get_cbor_float_prefix(double /*unused*/) { return static_cast(0xFB); // Double-Precision Float } - static constexpr CharType get_msgpack_float_prefix(float) + static constexpr CharType get_msgpack_float_prefix(float /*unused*/) { return static_cast(0xCA); // float 32 } - static constexpr CharType get_msgpack_float_prefix(double) + static constexpr CharType get_msgpack_float_prefix(double /*unused*/) { return static_cast(0xCB); // float 64 } - static constexpr CharType get_ubjson_float_prefix(float) + static constexpr CharType get_ubjson_float_prefix(float /*unused*/) { return 'd'; // float 32 } - static constexpr CharType get_ubjson_float_prefix(double) + static constexpr CharType get_ubjson_float_prefix(double /*unused*/) { return 'D'; // float 64 } @@ -8611,8 +8612,8 @@ class binary_writer /// the output output_adapter_t oa = nullptr; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -8682,10 +8683,9 @@ struct diyfp // f * 2^e { static constexpr int kPrecision = 64; // = q - uint64_t f; - int e; + uint64_t f = 0; + int e = 0; - constexpr diyfp() noexcept : f(0), e(0) {} constexpr diyfp(uint64_t f_, int e_) noexcept : f(f_), e(e_) {} /*! @@ -8697,7 +8697,7 @@ struct diyfp // f * 2^e assert(x.e == y.e); assert(x.f >= y.f); - return diyfp(x.f - y.f, x.e); + return {x.f - y.f, x.e}; } /*! @@ -8762,7 +8762,7 @@ struct diyfp // f * 2^e const uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32); - return diyfp(h, x.e + y.e + 64); + return {h, x.e + y.e + 64}; } /*! @@ -8793,7 +8793,7 @@ struct diyfp // f * 2^e assert(delta >= 0); assert(((x.f << delta) >> delta) == x.f); - return diyfp(x.f << delta, target_exponent); + return {x.f << delta, target_exponent}; } }; @@ -9096,7 +9096,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e) assert(e >= -1500); assert(e <= 1500); const int f = kAlpha - e - 1; - const int k = (f * 78913) / (1 << 18) + (f > 0); + const int k = (f * 78913) / (1 << 18) + static_cast(f > 0); const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep; assert(index >= 0); @@ -9244,7 +9244,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, 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.) + auto 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 // 1) @@ -9563,7 +9563,7 @@ inline char* append_exponent(char* buf, int e) *buf++ = '+'; } - uint32_t k = static_cast(e); + auto k = static_cast(e); if (k < 10) { // Always print at least two digits in the exponent. @@ -9681,7 +9681,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation. @note The result is NOT null-terminated. */ template -char* to_chars(char* first, char* last, FloatType value) +char* to_chars(char* first, const char* last, FloatType value) { static_cast(last); // maybe unused - fix warning assert(std::isfinite(value)); @@ -9771,6 +9771,9 @@ class serializer // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; + serializer(serializer&&) noexcept = default; + serializer& operator=(serializer&&) noexcept = default; + ~serializer() = default; /*! @brief internal implementation of the serialization function @@ -10345,8 +10348,8 @@ class serializer /// the indentation string string_t indent_string; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -10382,9 +10385,11 @@ class json_ref {} // class should be movable only - json_ref(json_ref&&) = default; + json_ref(json_ref&&) noexcept = default; json_ref(const json_ref&) = delete; json_ref& operator=(const json_ref&) = delete; + json_ref& operator=(json_ref&&) noexcept = default; + ~json_ref() = default; value_type moved_or_copied() const { @@ -10410,8 +10415,8 @@ class json_ref value_type* value_ref = nullptr; const bool is_rvalue; }; -} -} +} // namespace detail +} // namespace nlohmann // #include @@ -11112,7 +11117,7 @@ class json_pointer /// the reference tokens std::vector reference_tokens; }; -} +} // namespace nlohmann // #include @@ -11165,7 +11170,7 @@ struct adl_serializer ::nlohmann::to_json(j, std::forward(val)); } }; -} +} // namespace nlohmann /*! @@ -12964,7 +12969,7 @@ class basic_json @since version 1.0.0 */ - reference& operator=(basic_json other) noexcept ( + basic_json& operator=(basic_json other) noexcept ( std::is_nothrow_move_constructible::value and std::is_nothrow_move_assignable::value and std::is_nothrow_move_constructible::value and From 3abb788139303f131681656d842fdb2aa92dd2f8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 7 Oct 2018 19:07:58 +0200 Subject: [PATCH 4/6] :rotating_light: fixed some more clang-tidy warnings --- include/nlohmann/detail/input/json_sax.hpp | 73 +++++++------ include/nlohmann/detail/input/lexer.hpp | 12 +-- include/nlohmann/detail/input/parser.hpp | 7 +- .../nlohmann/detail/output/binary_writer.hpp | 24 ++--- include/nlohmann/json.hpp | 8 +- single_include/nlohmann/json.hpp | 100 ++++++++---------- 6 files changed, 102 insertions(+), 122 deletions(-) diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 8cc18abc2a..ca2ce30acc 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -286,20 +286,19 @@ class json_sax_dom_parser root = BasicJsonType(std::forward(v)); return &root; } + + assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); + + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->emplace_back(std::forward(v)); + return &(ref_stack.back()->m_value.array->back()); + } else { - assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); - if (ref_stack.back()->is_array()) - { - ref_stack.back()->m_value.array->emplace_back(std::forward(v)); - return &(ref_stack.back()->m_value.array->back()); - } - else - { - assert(object_element); - *object_element = BasicJsonType(std::forward(v)); - return object_element; - } + assert(object_element); + *object_element = BasicJsonType(std::forward(v)); + return object_element; } } @@ -574,37 +573,37 @@ class json_sax_dom_callback_parser root = std::move(value); return {true, &root}; } + + // skip this value if we already decided to skip the parent + // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) + if (not ref_stack.back()) + { + return {false, nullptr}; + } + + // we now only expect arrays and objects + assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); + + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->push_back(std::move(value)); + return {true, &(ref_stack.back()->m_value.array->back())}; + } else { - // skip this value if we already decided to skip the parent - // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) - if (not ref_stack.back()) - { - return {false, nullptr}; - } + // check if we should store an element for the current key + assert(not key_keep_stack.empty()); + const bool store_element = key_keep_stack.back(); + key_keep_stack.pop_back(); - assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); - if (ref_stack.back()->is_array()) + if (not store_element) { - ref_stack.back()->m_value.array->push_back(std::move(value)); - return {true, &(ref_stack.back()->m_value.array->back())}; + return {false, nullptr}; } - else - { - // check if we should store an element for the current key - assert(not key_keep_stack.empty()); - const bool store_element = key_keep_stack.back(); - key_keep_stack.pop_back(); - - if (not store_element) - { - return {false, nullptr}; - } - assert(object_element); - *object_element = std::move(value); - return {true, object_element}; - } + assert(object_element); + *object_element = std::move(value); + return {true, object_element}; } } diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 4470e932f8..4204ab2430 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1214,13 +1214,11 @@ class lexer // check if we completely parse the BOM return get() == 0xBB and get() == 0xBF; } - else - { - // the first character is not the beginning of the BOM; unget it to - // process is later - unget(); - return true; - } + + // the first character is not the beginning of the BOM; unget it to + // process is later + unget(); + return true; } token_type scan() diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index 1ee1e6bf20..c354a7b521 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -201,12 +201,9 @@ class parser m_lexer.get_token_string(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string))); } - else + if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) { - if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) - { - return false; - } + return false; } // parse separator (:) diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 17df41d831..b93dc6a3ce 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -851,22 +851,20 @@ class binary_writer { return 'i'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'U'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'I'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'l'; } - else // no check and assume int64_t (see note above) - { - return 'L'; - } + // no check and assume int64_t (see note above) + return 'L'; } case value_t::number_unsigned: @@ -875,22 +873,20 @@ class binary_writer { return 'i'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'U'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'I'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'l'; } - else // no check and assume int64_t (see note above) - { - return 'L'; - } + // no check and assume int64_t (see note above) + return 'L'; } case value_t::number_float: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0b6a6fb5a1..f58cef14fe 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -7289,11 +7289,9 @@ class basic_json // avoid undefined behavior JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); } - else - { - // default case: insert add offset - parent.insert(parent.begin() + static_cast(idx), val); - } + + // default case: insert add offset + parent.insert(parent.begin() + static_cast(idx), val); } break; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 210fc88c38..7abcb127ca 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3483,13 +3483,11 @@ class lexer // check if we completely parse the BOM return get() == 0xBB and get() == 0xBF; } - else - { - // the first character is not the beginning of the BOM; unget it to - // process is later - unget(); - return true; - } + + // the first character is not the beginning of the BOM; unget it to + // process is later + unget(); + return true; } token_type scan() @@ -4048,20 +4046,19 @@ class json_sax_dom_parser root = BasicJsonType(std::forward(v)); return &root; } + + assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); + + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->emplace_back(std::forward(v)); + return &(ref_stack.back()->m_value.array->back()); + } else { - assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); - if (ref_stack.back()->is_array()) - { - ref_stack.back()->m_value.array->emplace_back(std::forward(v)); - return &(ref_stack.back()->m_value.array->back()); - } - else - { - assert(object_element); - *object_element = BasicJsonType(std::forward(v)); - return object_element; - } + assert(object_element); + *object_element = BasicJsonType(std::forward(v)); + return object_element; } } @@ -4336,37 +4333,37 @@ class json_sax_dom_callback_parser root = std::move(value); return {true, &root}; } + + // skip this value if we already decided to skip the parent + // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) + if (not ref_stack.back()) + { + return {false, nullptr}; + } + + // we now only expect arrays and objects + assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); + + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->push_back(std::move(value)); + return {true, &(ref_stack.back()->m_value.array->back())}; + } else { - // skip this value if we already decided to skip the parent - // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) - if (not ref_stack.back()) - { - return {false, nullptr}; - } + // check if we should store an element for the current key + assert(not key_keep_stack.empty()); + const bool store_element = key_keep_stack.back(); + key_keep_stack.pop_back(); - assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); - if (ref_stack.back()->is_array()) + if (not store_element) { - ref_stack.back()->m_value.array->push_back(std::move(value)); - return {true, &(ref_stack.back()->m_value.array->back())}; + return {false, nullptr}; } - else - { - // check if we should store an element for the current key - assert(not key_keep_stack.empty()); - const bool store_element = key_keep_stack.back(); - key_keep_stack.pop_back(); - - if (not store_element) - { - return {false, nullptr}; - } - assert(object_element); - *object_element = std::move(value); - return {true, object_element}; - } + assert(object_element); + *object_element = std::move(value); + return {true, object_element}; } } @@ -4654,12 +4651,9 @@ class parser m_lexer.get_token_string(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string))); } - else + if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) { - if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) - { - return false; - } + return false; } // parse separator (:) @@ -18392,11 +18386,9 @@ class basic_json // avoid undefined behavior JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); } - else - { - // default case: insert add offset - parent.insert(parent.begin() + static_cast(idx), val); - } + + // default case: insert add offset + parent.insert(parent.begin() + static_cast(idx), val); } break; } From 6e49d9f5ffb1f07b813e7ff1bad0ca80265a4a49 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 7 Oct 2018 21:34:40 +0200 Subject: [PATCH 5/6] :ambulance: fixed compilation error --- include/nlohmann/detail/input/lexer.hpp | 4 +-- include/nlohmann/detail/output/serializer.hpp | 4 +-- single_include/nlohmann/json.hpp | 32 ++++++++----------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 4204ab2430..362b4f23ab 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -104,9 +104,9 @@ class lexer // delete because of pointer members lexer(const lexer&) = delete; - lexer(lexer&&) noexcept = default; + lexer(lexer&&) = delete; lexer& operator=(lexer&) = delete; - lexer& operator=(lexer&&) noexcept = default; + lexer& operator=(lexer&&) = delete; ~lexer() = default; private: diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 6088ebe893..bb74a86e65 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -53,8 +53,8 @@ class serializer // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; - serializer(serializer&&) noexcept = default; - serializer& operator=(serializer&&) noexcept = default; + serializer(serializer&&) = delete; + serializer& operator=(serializer&&) = delete; ~serializer() = default; /*! diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7abcb127ca..583eb87455 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2373,9 +2373,9 @@ class lexer // delete because of pointer members lexer(const lexer&) = delete; - lexer(lexer&&) noexcept = default; + lexer(lexer&&) = delete; lexer& operator=(lexer&) = delete; - lexer& operator=(lexer&&) noexcept = default; + lexer& operator=(lexer&&) = delete; ~lexer() = default; private: @@ -8510,22 +8510,20 @@ class binary_writer { return 'i'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'U'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'I'; } - else if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) + if ((std::numeric_limits::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits::max)()) { return 'l'; } - else // no check and assume int64_t (see note above) - { - return 'L'; - } + // no check and assume int64_t (see note above) + return 'L'; } case value_t::number_unsigned: @@ -8534,22 +8532,20 @@ class binary_writer { return 'i'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'U'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'I'; } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) { return 'l'; } - else // no check and assume int64_t (see note above) - { - return 'L'; - } + // no check and assume int64_t (see note above) + return 'L'; } case value_t::number_float: @@ -9765,8 +9761,8 @@ class serializer // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; - serializer(serializer&&) noexcept = default; - serializer& operator=(serializer&&) noexcept = default; + serializer(serializer&&) = delete; + serializer& operator=(serializer&&) = delete; ~serializer() = default; /*! From 6d34d64bfdb1b06e5a80ac14b35abddd0006d9c5 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 8 Oct 2018 06:54:51 +0200 Subject: [PATCH 6/6] :ambulance: fixed compilation error --- include/nlohmann/detail/json_ref.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/json_ref.hpp b/include/nlohmann/detail/json_ref.hpp index b9abc47af1..f9dba5def4 100644 --- a/include/nlohmann/detail/json_ref.hpp +++ b/include/nlohmann/detail/json_ref.hpp @@ -31,10 +31,10 @@ class json_ref {} // class should be movable only - json_ref(json_ref&&) noexcept = default; + json_ref(json_ref&&) = default; json_ref(const json_ref&) = delete; json_ref& operator=(const json_ref&) = delete; - json_ref& operator=(json_ref&&) noexcept = default; + json_ref& operator=(json_ref&&) = delete; ~json_ref() = default; value_type moved_or_copied() const diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 583eb87455..d4422c59f4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10375,10 +10375,10 @@ class json_ref {} // class should be movable only - json_ref(json_ref&&) noexcept = default; + json_ref(json_ref&&) = default; json_ref(const json_ref&) = delete; json_ref& operator=(const json_ref&) = delete; - json_ref& operator=(json_ref&&) noexcept = default; + json_ref& operator=(json_ref&&) = delete; ~json_ref() = default; value_type moved_or_copied() const