Skip to content

Commit

Permalink
💄 clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jan 2, 2017
1 parent a3063c2 commit d173517
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,17 @@ class basic_json
break;
}

case value_t::null:
{
break;
}

default:
{
if (t == value_t::null)
{
throw std::domain_error("961c151d2e87f2686a955a9be24d316f1362bf21"); // LCOV_EXCL_LINE
}
break;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,17 @@ class basic_json
break;
}

case value_t::null:
{
break;
}

default:
{
if (t == value_t::null)
{
throw std::domain_error("961c151d2e87f2686a955a9be24d316f1362bf21"); // LCOV_EXCL_LINE
}
break;
}
}
Expand Down
20 changes: 16 additions & 4 deletions test/src/unit-allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
auto t = my_json::value_t::object;
auto clean_up = [](my_json::json_value& j){ my_allocator_clean_up(j.object); };
auto clean_up = [](my_json::json_value & j)
{
my_allocator_clean_up(j.object);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
Expand All @@ -151,7 +154,10 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
auto t = my_json::value_t::array;
auto clean_up = [](my_json::json_value& j){ my_allocator_clean_up(j.array); };
auto clean_up = [](my_json::json_value & j)
{
my_allocator_clean_up(j.array);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
Expand All @@ -161,7 +167,10 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
auto t = my_json::value_t::string;
auto clean_up = [](my_json::json_value& j){ my_allocator_clean_up(j.string); };
auto clean_up = [](my_json::json_value & j)
{
my_allocator_clean_up(j.string);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
Expand All @@ -173,7 +182,10 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
my_json::string_t v("foo");
auto clean_up = [](my_json::json_value& j){ my_allocator_clean_up(j.string); };
auto clean_up = [](my_json::json_value & j)
{
my_allocator_clean_up(j.string);
};
CHECK_NOTHROW(my_json::json_value j(v); clean_up(j));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(v), std::bad_alloc);
Expand Down

0 comments on commit d173517

Please sign in to comment.