Removed JsonVariant::as<char>() (fixes #1498)

This commit is contained in:
Benoit Blanchon
2021-02-18 08:48:10 +01:00
parent e22d4bf31f
commit 5234c8124b
6 changed files with 48 additions and 4 deletions

View File

@ -53,7 +53,8 @@ struct VariantConstAs<ArrayRef> {
// ---
template <typename T>
inline typename enable_if<is_integral<T>::value && !is_same<bool, T>::value,
inline typename enable_if<is_integral<T>::value && !is_same<bool, T>::value &&
!is_same<char, T>::value,
T>::type
variantAs(const VariantData* data) {
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);

View File

@ -251,6 +251,20 @@ class VariantRef : public VariantRefBase<VariantData>,
template <typename T>
FORCE_INLINE typename VariantAs<T>::type as() const {
/********************************************************************
** 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 extract the wrong value type. **
** **
** For example: **
** char* name = doc["name"]; **
** char age = doc["age"]; **
** Instead, use: **
** const char* name = doc["name"]; **
** int8_t age = doc["age"]; **
********************************************************************/
return variantAs<typename VariantAs<T>::type>(_data, _pool);
}