diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 6a56b3453..b3dc8787c 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -349,7 +349,7 @@ class json_sax_dom_error_state return false; } - constexpr bool is_errored() const + bool is_errored() const { return errored; } diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index f06488c99..50132bdde 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -168,7 +168,7 @@ class parser return finish_input(*sax, strict); } - return result; + return false; } private: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 228084a5a..c0111a6dd 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -55,7 +55,7 @@ #include // IWYU pragma: export #include // IWYU pragma: keep #include // IWYU pragma: keep -#include +#include // IWYU pragma: export #include #include #include @@ -3144,8 +3144,12 @@ public: { std::vector result; result.reserve(detail::binary_initial_capacity(j)); - auto writer = vector_writer(result, error_handler); - write(writer); + { + // the sink sets the size of result when it is destroyed, which + // must happen before result is returned (without NRVO, it is moved) + auto writer = vector_writer(result, error_handler); + write(writer); + } return result; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 92468f89e..219901b85 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -8255,7 +8255,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // IWYU pragma: keep // #include - +// IWYU pragma: export // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ @@ -15390,7 +15390,7 @@ class json_sax_dom_error_state return false; } - constexpr bool is_errored() const + bool is_errored() const { return errored; } @@ -21024,7 +21024,7 @@ class parser return finish_input(*sax, strict); } - return result; + return false; } private: @@ -37855,8 +37855,12 @@ public: { std::vector result; result.reserve(detail::binary_initial_capacity(j)); - auto writer = vector_writer(result, error_handler); - write(writer); + { + // the sink sets the size of result when it is destroyed, which + // must happen before result is returned (without NRVO, it is moved) + auto writer = vector_writer(result, error_handler); + write(writer); + } return result; }