diff --git a/CHANGELOG.md b/CHANGELOG.md index eebcb0c5..1c3a7d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ ArduinoJson: change log HEAD ---- -* Removed `JsonVariant::as()` (issue #1498) +* Removed support for `char` values, see below (issue #1498) -> ### BREAKING CHANGE +> ### BREAKING CHANGES > > We cannot cast a `JsonVariant` to a `char` anymore, so the following will break: > ```c++ @@ -16,6 +16,17 @@ HEAD > ```c++ > int8_t age = doc["age"]; // OK > ``` +> +> Similarly, we cannot assign from a `char` anymore, so the following will break: +> ```c++ +> char age; +> doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)' +> ``` +> Instead, you must use another integral type, such as `int8_t`: +> ```c++ +> int8_t age; +> doc["age"] = age; // OK +> ``` v6.17.3 (2021-02-15) ------- diff --git a/extras/tests/FailingBuilds/CMakeLists.txt b/extras/tests/FailingBuilds/CMakeLists.txt index 19fdb23b..03152058 100644 --- a/extras/tests/FailingBuilds/CMakeLists.txt +++ b/extras/tests/FailingBuilds/CMakeLists.txt @@ -43,3 +43,5 @@ build_should_fail(delete_jsondocument) add_executable(variant_as_char variant_as_char.cpp) build_should_fail(variant_as_char) +add_executable(assign_char assign_char.cpp) +build_should_fail(assign_char) diff --git a/extras/tests/FailingBuilds/assign_char.cpp b/extras/tests/FailingBuilds/assign_char.cpp new file mode 100644 index 00000000..b31f055a --- /dev/null +++ b/extras/tests/FailingBuilds/assign_char.cpp @@ -0,0 +1,12 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#include + +// See issue #1498 + +int main() { + DynamicJsonDocument doc(1024); + doc["dummy"] = 'A'; +} diff --git a/src/ArduinoJson/Object/MemberProxy.hpp b/src/ArduinoJson/Object/MemberProxy.hpp index 0f73c852..c3cd9d51 100644 --- a/src/ArduinoJson/Object/MemberProxy.hpp +++ b/src/ArduinoJson/Object/MemberProxy.hpp @@ -46,6 +46,20 @@ class MemberProxy : public VariantOperators >, template FORCE_INLINE typename enable_if::value, this_type &>::type operator=(const TValue &src) { + /******************************************************************** + ** THIS IS NOT A BUG IN THE LIBRARY ** + ** -------------------------------- ** + ** Get a compilation error pointing here? ** + ** It doesn't mean the error *is* here. ** + ** Often, it's because you try to assign the wrong value type. ** + ** ** + ** For example: ** + ** char age = 42 ** + ** doc["age"] = age; ** + ** Instead, use: ** + ** int8_t age = 42; ** + ** doc["age"] = age; ** + ********************************************************************/ getOrAddUpstreamMember().set(src); return *this; } diff --git a/src/ArduinoJson/Variant/VariantRef.hpp b/src/ArduinoJson/Variant/VariantRef.hpp index 48a89ec6..68a37d44 100644 --- a/src/ArduinoJson/Variant/VariantRef.hpp +++ b/src/ArduinoJson/Variant/VariantRef.hpp @@ -186,8 +186,9 @@ class VariantRef : public VariantRefBase, // set(unsigned long) template FORCE_INLINE bool set( - T value, typename enable_if::value && - !is_same::value>::type * = 0) const { + T value, + typename enable_if::value && !is_same::value && + !is_same::value>::type * = 0) const { return variantSetInteger(_data, value); }