Rename two more json_view test helpers that clash in the unity build

In one batch, the exception_of() calls of unit-json_view_image.cpp bind
to the exception_of(F) template of unit-json_view.cpp, so GCC reports the
file's own exception_of() as unused (-Werror=unused-function), and a loop
variable counter in unit-json_view_image.cpp hides the counter of
unit-json_view_edit.cpp (MSVC C4459).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-21 15:17:30 +02:00
1 parent 52724f5ae5
commit 3250b5ce46
2 files changed
+9 -9

No files matched your search

+3 -3
View File
@@ -52,7 +52,7 @@ int r(int n)
return static_cast<int>(edit_rng() % static_cast<unsigned>(n));
}
int counter = 0;
int edit_counter = 0;
std::uint64_t edit_bits(double x)
{
@@ -103,7 +103,7 @@ ordered_json random_value(int depth)
ordered_json o = ordered_json::object();
for (int i = r(5); i > 0; --i)
{
o[random_string() + "#" + std::to_string(counter++)] = random_value(depth + 1);
o[random_string() + "#" + std::to_string(edit_counter++)] = random_value(depth + 1);
}
return o;
}
@@ -435,7 +435,7 @@ TEST_CASE("json_view edits: differential")
}
else if ((op == 4 || op == 5) && target.is_object()) // set a member (new or existing)
{
std::string key = random_string() + "#" + std::to_string(counter++);
std::string key = random_string() + "#" + std::to_string(edit_counter++);
if (op == 5 && !target.empty())
{
key = std::next(target.begin(), r(static_cast<int>(target.size()))).key();
+6 -6
View File
@@ -38,7 +38,7 @@ using nlohmann::detail::view::node;
namespace
{
#if !defined(JSON_NOEXCEPTION)
std::string exception_of(const std::function<void()>& f)
std::string image_exception_of(const std::function<void()>& f)
{
try
{
@@ -119,7 +119,7 @@ void set_node(std::vector<std::uint8_t>& image, std::size_t i, const node& n)
/// the result of loading an image with a check: "" or the exception message
std::string load_result(const std::vector<std::uint8_t>& image, image_check check)
{
return exception_of([&]
return image_exception_of([&]
{
const json_document d = json_document::load(image, check);
static_cast<void>(d);
@@ -701,9 +701,9 @@ TEST_CASE("json_view images: errors")
SECTION("saving a discarded document")
{
const json_document empty{};
CHECK(exception_of([&] { static_cast<void>(empty.save()); }) == "[json.exception.type_error.320] cannot save a discarded json_document");
CHECK(image_exception_of([&] { static_cast<void>(empty.save()); }) == "[json.exception.type_error.320] cannot save a discarded json_document");
const json_document failed = json_document::parse("[1,", false);
CHECK(exception_of([&] { static_cast<void>(failed.save()); }) == "[json.exception.type_error.320] cannot save a discarded json_document");
CHECK(image_exception_of([&] { static_cast<void>(failed.save()); }) == "[json.exception.type_error.320] cannot save a discarded json_document");
}
const std::vector<std::uint8_t> image = json_document::parse(R"({"a": [1, "\u00e9"]})").save();
@@ -711,12 +711,12 @@ TEST_CASE("json_view images: errors")
SECTION("header and sizes")
{
CHECK(exception_of([]
CHECK(image_exception_of([]
{
const json_document d = json_document::load(nullptr, 0);
static_cast<void>(d);
}) == prefix + "too short");
CHECK(exception_of([&]
CHECK(image_exception_of([&]
{
const json_document d = json_document::load(image.data(), 63);
static_cast<void>(d);