From 943a902a0bbb4c73111e0c2d8d97afd4960ff2b5 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 23 Oct 2021 16:12:58 +0200 Subject: [PATCH] Remove `DeserializationError == bool` and `DeserializationError != bool` --- CHANGELOG.md | 1 + .../JsonDeserializer/DeserializationError.cpp | 44 +++++++------------ .../Deserialization/DeserializationError.hpp | 12 ----- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77dc0926..13a7ead5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ HEAD * Change the default of `ARDUINOJSON_USE_LONG_LONG` to `1` on 32-bit platforms * Add `as()` and `is()` * Add safe bool idiom in `JsonString` +* Remove `DeserializationError == bool` and `DeserializationError != bool` v6.18.5 (2021-09-28) ------- diff --git a/extras/tests/JsonDeserializer/DeserializationError.cpp b/extras/tests/JsonDeserializer/DeserializationError.cpp index 3e792900..688a90b3 100644 --- a/extras/tests/JsonDeserializer/DeserializationError.cpp +++ b/extras/tests/JsonDeserializer/DeserializationError.cpp @@ -11,14 +11,14 @@ void testStringification(DeserializationError error, std::string expected) { void testBoolification(DeserializationError error, bool expected) { // DeserializationError on left-hand side - CHECK(error == expected); - CHECK(error != !expected); - CHECK(!error == !expected); + CHECK(bool(error) == expected); + CHECK(bool(error) != !expected); + CHECK(!bool(error) == !expected); // DeserializationError on right-hand side - CHECK(expected == error); - CHECK(!expected != error); - CHECK(!expected == !error); + CHECK(expected == bool(error)); + CHECK(!expected != bool(error)); + CHECK(!expected == !bool(error)); } #define TEST_STRINGIFICATION(symbol) \ @@ -70,34 +70,24 @@ TEST_CASE("DeserializationError") { } } - SECTION("Comparisons") { + SECTION("Use in a condition") { DeserializationError invalidInput(DeserializationError::InvalidInput); DeserializationError ok(DeserializationError::Ok); - SECTION("DeserializationError == bool") { - REQUIRE(invalidInput == true); - REQUIRE(ok == false); + SECTION("if (!err)") { + if (!invalidInput) + FAIL(); } - SECTION("bool == DeserializationError") { - REQUIRE(true == invalidInput); - REQUIRE(false == ok); + SECTION("if (err)") { + if (ok) + FAIL(); } + } - SECTION("DeserializationError != bool") { - REQUIRE(invalidInput != false); - REQUIRE(ok != true); - } - - SECTION("bool != DeserializationError") { - REQUIRE(false != invalidInput); - REQUIRE(true != ok); - } - - SECTION("Negations") { - REQUIRE(!invalidInput == false); - REQUIRE(!ok == true); - } + SECTION("Comparisons") { + DeserializationError invalidInput(DeserializationError::InvalidInput); + DeserializationError ok(DeserializationError::Ok); SECTION("DeserializationError == Code") { REQUIRE(invalidInput == DeserializationError::InvalidInput); diff --git a/src/ArduinoJson/Deserialization/DeserializationError.hpp b/src/ArduinoJson/Deserialization/DeserializationError.hpp index 5248a471..e225217e 100644 --- a/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -57,18 +57,6 @@ class DeserializationError : public SafeBoolIdom { operator bool_type() const { return _code != Ok ? safe_true() : safe_false(); } - friend bool operator==(bool value, const DeserializationError& err) { - return static_cast(err) == value; - } - friend bool operator==(const DeserializationError& err, bool value) { - return static_cast(err) == value; - } - friend bool operator!=(bool value, const DeserializationError& err) { - return static_cast(err) != value; - } - friend bool operator!=(const DeserializationError& err, bool value) { - return static_cast(err) != value; - } // Returns internal enum, useful for switch statement Code code() const {