mirror of
https://github.com/nlohmann/json.git
synced 2026-10-22 22:08:55 +00:00
Let the json_view error replay handler return from parse_error()
sax_parse() recovers from an error if parse_error() returns true. For a handler whose parse_error() is [[noreturn]], MSVC reports that code as unreachable (C4702), which fails the /WX module build. throwing_sax now throws under a flag, as json_sax_dom_parser does. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+24
-4
No files matched your search
@@ -124,11 +124,21 @@ struct throwing_sax
|
||||
|
||||
/// (a template, as in json_sax_dom_parser: the parser passes the concrete
|
||||
/// exception type, which is thrown as is)
|
||||
///
|
||||
/// It is not [[noreturn]]: sax_parse() recovers from an error if
|
||||
/// parse_error() returns true, and MSVC reports that code as unreachable
|
||||
/// (C4702) for a handler that never returns. The flag hides that from it.
|
||||
template<class Exception>
|
||||
[[noreturn]] bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
{
|
||||
NLOHMANN_VIEW_THROW(ex);
|
||||
if (throwing)
|
||||
{
|
||||
NLOHMANN_VIEW_THROW(ex);
|
||||
}
|
||||
return false; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
bool throwing = true;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Generated
+12
-2
@@ -2768,11 +2768,21 @@ struct throwing_sax
|
||||
|
||||
/// (a template, as in json_sax_dom_parser: the parser passes the concrete
|
||||
/// exception type, which is thrown as is)
|
||||
///
|
||||
/// It is not [[noreturn]]: sax_parse() recovers from an error if
|
||||
/// parse_error() returns true, and MSVC reports that code as unreachable
|
||||
/// (C4702) for a handler that never returns. The flag hides that from it.
|
||||
template<class Exception>
|
||||
[[noreturn]] bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
{
|
||||
NLOHMANN_VIEW_THROW(ex);
|
||||
if (throwing)
|
||||
{
|
||||
NLOHMANN_VIEW_THROW(ex);
|
||||
}
|
||||
return false; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
bool throwing = true;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Reference in new issue
Block a user