Fix CI: unused parameter without exceptions, cpplint, BUILD.bazel
- json_sax_error_reporter::parse_error: mark the exception unused, as JSON_THROW does not use it with JSON_NOEXCEPTION - unit-contiguous_parser.cpp: compare the exceptions of both paths only when exceptions are enabled (invalid input aborted the test otherwise) - silence cpplint's readability/braces false positives on the if statements inside the parser's macros - add contiguous_parser.hpp to BUILD.bazel Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
4 files changed
+18
-14
No files matched your search
@@ -30,6 +30,7 @@ cc_library(
|
||||
"include/nlohmann/detail/exceptions.hpp",
|
||||
"include/nlohmann/detail/hash.hpp",
|
||||
"include/nlohmann/detail/input/binary_reader.hpp",
|
||||
"include/nlohmann/detail/input/contiguous_parser.hpp",
|
||||
"include/nlohmann/detail/input/input_adapters.hpp",
|
||||
"include/nlohmann/detail/input/json_sax.hpp",
|
||||
"include/nlohmann/detail/input/lexer.hpp",
|
||||
|
||||
@@ -120,7 +120,7 @@ class contiguous_parser
|
||||
#define JSON_CONTIGUOUS_OPEN(is_object) \
|
||||
do \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(depth != 0 && (depth % 64) == 0)) \
|
||||
if (JSON_HEDLEY_UNLIKELY(depth != 0 && (depth % 64) == 0)) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
outer.push_back(kinds); \
|
||||
kinds = 0; \
|
||||
@@ -226,13 +226,13 @@ class contiguous_parser
|
||||
// what may follow a value in an array: a comma and the next value, or the end
|
||||
#define JSON_CONTIGUOUS_AFTER_ELEMENT \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
goto array_value; \
|
||||
} \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ']')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ']')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
if (JSON_HEDLEY_UNLIKELY(!report(sax->end_array()))) \
|
||||
@@ -246,13 +246,13 @@ class contiguous_parser
|
||||
// what may follow a value in an object: a comma and the next member, or the end
|
||||
#define JSON_CONTIGUOUS_AFTER_MEMBER \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
goto object_key; \
|
||||
} \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == '}')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == '}')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
if (JSON_HEDLEY_UNLIKELY(!report(sax->end_object()))) \
|
||||
@@ -836,6 +836,7 @@ class json_sax_error_reporter : public json_sax_acceptor<BasicJsonType>
|
||||
template<class Exception>
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
{
|
||||
static_cast<void>(ex); // (unused without exceptions)
|
||||
if (allow_exceptions)
|
||||
{
|
||||
JSON_THROW(ex);
|
||||
|
||||
Generated
+6
-5
@@ -23962,7 +23962,7 @@ class contiguous_parser
|
||||
#define JSON_CONTIGUOUS_OPEN(is_object) \
|
||||
do \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(depth != 0 && (depth % 64) == 0)) \
|
||||
if (JSON_HEDLEY_UNLIKELY(depth != 0 && (depth % 64) == 0)) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
outer.push_back(kinds); \
|
||||
kinds = 0; \
|
||||
@@ -24068,13 +24068,13 @@ class contiguous_parser
|
||||
// what may follow a value in an array: a comma and the next value, or the end
|
||||
#define JSON_CONTIGUOUS_AFTER_ELEMENT \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
goto array_value; \
|
||||
} \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ']')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ']')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
if (JSON_HEDLEY_UNLIKELY(!report(sax->end_array()))) \
|
||||
@@ -24088,13 +24088,13 @@ class contiguous_parser
|
||||
// what may follow a value in an object: a comma and the next member, or the end
|
||||
#define JSON_CONTIGUOUS_AFTER_MEMBER \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == ',')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
JSON_CONTIGUOUS_WS(); \
|
||||
goto object_key; \
|
||||
} \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == '}')) \
|
||||
if (JSON_HEDLEY_LIKELY(JSON_CONTIGUOUS_CUR() == '}')) /* NOLINT(readability/braces) */ \
|
||||
{ \
|
||||
++p; \
|
||||
if (JSON_HEDLEY_UNLIKELY(!report(sax->end_object()))) \
|
||||
@@ -24678,6 +24678,7 @@ class json_sax_error_reporter : public json_sax_acceptor<BasicJsonType>
|
||||
template<class Exception>
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||
{
|
||||
static_cast<void>(ex); // (unused without exceptions)
|
||||
if (allow_exceptions)
|
||||
{
|
||||
JSON_THROW(ex);
|
||||
|
||||
@@ -86,10 +86,10 @@ std::string describe_value(const Json& j, int depth = 0)
|
||||
return out;
|
||||
}
|
||||
|
||||
#if !defined(JSON_NOEXCEPTION)
|
||||
template<typename Json, typename Parse>
|
||||
std::string outcome(Parse parse)
|
||||
{
|
||||
#if !defined(JSON_NOEXCEPTION)
|
||||
try
|
||||
{
|
||||
return describe_value(parse());
|
||||
@@ -98,10 +98,8 @@ std::string outcome(Parse parse)
|
||||
{
|
||||
return std::string("exception: ") + e.what();
|
||||
}
|
||||
#else
|
||||
return describe_value(parse());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/// every SAX event with its values, the text of float tokens, and the parse
|
||||
/// error with its position, token and message; returns false after
|
||||
@@ -220,6 +218,8 @@ void check_same(const std::string& text)
|
||||
CAPTURE(text)
|
||||
const std::list<char> bytes(text.begin(), text.end());
|
||||
|
||||
#if !defined(JSON_NOEXCEPTION)
|
||||
// with exceptions: the value, or the same exception for both
|
||||
const std::string contiguous = outcome<Json>([&]
|
||||
{
|
||||
return Json::parse(text);
|
||||
@@ -229,6 +229,7 @@ void check_same(const std::string& text)
|
||||
return Json::parse(bytes.begin(), bytes.end());
|
||||
});
|
||||
CHECK(contiguous == byte_path);
|
||||
#endif
|
||||
|
||||
// without exceptions: the value, or discarded for both
|
||||
const Json c = Json::parse(text, nullptr, false);
|
||||
|
||||
Reference in new issue
Block a user