Remove JsonVariant::set(char)

This commit is contained in:
Benoit Blanchon
2021-02-07 11:40:14 +01:00
parent 5234c8124b
commit 54d4b308f4
5 changed files with 44 additions and 4 deletions

View File

@ -4,9 +4,9 @@ ArduinoJson: change log
HEAD
----
* Removed `JsonVariant::as<char>()` (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)
-------

View File

@ -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)

View File

@ -0,0 +1,12 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
// See issue #1498
int main() {
DynamicJsonDocument doc(1024);
doc["dummy"] = 'A';
}

View File

@ -46,6 +46,20 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
template <typename TValue>
FORCE_INLINE typename enable_if<!is_array<TValue>::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;
}

View File

@ -186,8 +186,9 @@ class VariantRef : public VariantRefBase<VariantData>,
// set(unsigned long)
template <typename T>
FORCE_INLINE bool set(
T value, typename enable_if<is_integral<T>::value &&
!is_same<bool, T>::value>::type * = 0) const {
T value,
typename enable_if<is_integral<T>::value && !is_same<bool, T>::value &&
!is_same<char, T>::value>::type * = 0) const {
return variantSetInteger<T>(_data, value);
}