1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-22 15:21:52 +03:00

fix #414 - comparing to 0 literal

Overload comparison operators for all types that could be converted
to nullptr.
This commit is contained in:
Mihai STAN
2017-01-03 00:49:33 +02:00
parent 9755cc75b1
commit 6198439f59
3 changed files with 490 additions and 996 deletions

View File

@ -663,4 +663,22 @@ TEST_CASE("regression tests")
std::vector<uint8_t> vec3 {0xbf, 0x61, 0x61, 0x01};
CHECK_THROWS_AS(json::from_cbor(vec3), std::out_of_range);
}
SECTION("issue #414 - compare with literal 0)")
{
#define CHECK_TYPE(v) \
CHECK((json(v) == v));\
CHECK((v == json(v)));\
CHECK_FALSE((json(v) != v));\
CHECK_FALSE((v != json(v)));
CHECK_TYPE(nullptr);
CHECK_TYPE(0);
CHECK_TYPE(0u);
CHECK_TYPE(0L);
CHECK_TYPE(0.0);
CHECK_TYPE("");
#undef CHECK_TYPE
}
}