From ddbdb65834fe82d648cdd00b9e2965dac7a0377d Mon Sep 17 00:00:00 2001 From: abbaswasim Date: Tue, 2 Mar 2021 01:42:33 +0000 Subject: [PATCH 1/3] Fix amount of entries in the json object After the initial j.push_back() calls there is another j.emplace_back() call that makes the size == 4 not 3. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d354f1ed..26f8a6069 100644 --- a/README.md +++ b/README.md @@ -580,7 +580,7 @@ bool foo = j.at(2); j == "[\"foo\", 42, true, 1.78]"_json; // true // other stuff -j.size(); // 3 entries +j.size(); // 4 entries j.empty(); // false j.type(); // json::value_t::array j.clear(); // the array is empty again From 0a9ec38f44c06513ebd396b133b35ee970291d4e Mon Sep 17 00:00:00 2001 From: Remy Jette Date: Mon, 15 Mar 2021 17:30:58 -0700 Subject: [PATCH 2/3] Remove HEDLEY annotation from exception::what() The latest MSVC compiler throws the following warning on nlohmann::detail::exception::what() if /analyze is enabled: ``` vcruntime_exception.h(93) : warning C28204: 'what' has an override at `nlohmann\json\develop\single_include\nlohmann\json.hpp(2644)` and only the override is annotated for return: when an override is annotated, the base (this function) should be similarly annotated. ``` See https://godbolt.org/z/r331h4 --- include/nlohmann/detail/exceptions.hpp | 1 - single_include/nlohmann/json.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 5c9dce3c5..bd0534c43 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -49,7 +49,6 @@ class exception : public std::exception { public: /// returns the explanatory string - JSON_HEDLEY_RETURNS_NON_NULL const char* what() const noexcept override { return m.what(); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a83971da2..d34b79005 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2640,7 +2640,6 @@ class exception : public std::exception { public: /// returns the explanatory string - JSON_HEDLEY_RETURNS_NON_NULL const char* what() const noexcept override { return m.what(); From 90d51b9205131106739ef06d09a75701eb4d406d Mon Sep 17 00:00:00 2001 From: Fraser Date: Thu, 18 Mar 2021 12:25:12 -0400 Subject: [PATCH 3/3] Update parse_exceptions.md Referring to https://github.com/nlohmann/json/blob/develop/doc/examples/parse_error.cpp and https://json.nlohmann.me/home/exceptions/ (and also based on testing), the catch command should reference `catch (json::parse_error& ex)` and not `catch (json::exception::parse_error& ex)` --- doc/mkdocs/docs/features/parsing/parse_exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mkdocs/docs/features/parsing/parse_exceptions.md b/doc/mkdocs/docs/features/parsing/parse_exceptions.md index b882e0b5c..f0569b8e2 100644 --- a/doc/mkdocs/docs/features/parsing/parse_exceptions.md +++ b/doc/mkdocs/docs/features/parsing/parse_exceptions.md @@ -8,7 +8,7 @@ try { j = json::parse(my_input); } -catch (json::exception::parse_error& ex) +catch (json::parse_error& ex) { std::cerr << "parse error at byte " << ex.byte << std::endl; }