Browse Source

Fix `function returns incomplete class type` on IAR (issue #2001)

Benoit Blanchon 2 năm trước cách đây
mục cha
commit
3e1be980d9

+ 5 - 0
CHANGELOG.md

@@ -1,6 +1,11 @@
 ArduinoJson: change log
 =======================
 
+HEAD
+----
+
+* Fix warning `function returns incomplete class type` on IAR (issue #2001)
+
 v6.21.4 (2023-12-07)
 -------
 

+ 30 - 0
src/ArduinoJson/Variant/VariantImpl.hpp

@@ -110,6 +110,13 @@ inline JsonVariant VariantRefBase<TDerived>::add() const {
                      variantAddElement(getOrCreateData(), getPool()));
 }
 
+template <typename TDerived>
+template <typename T>
+inline typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
+VariantRefBase<TDerived>::as() const {
+  return Converter<T>::fromJson(getVariant());
+}
+
 template <typename TDerived>
 inline JsonVariant VariantRefBase<TDerived>::getVariant() const {
   return JsonVariant(getPool(), getData());
@@ -120,6 +127,29 @@ inline JsonVariant VariantRefBase<TDerived>::getOrCreateVariant() const {
   return JsonVariant(getPool(), getOrCreateData());
 }
 
+template <typename TDerived>
+template <typename T>
+inline typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
+VariantRefBase<TDerived>::is() const {
+  return Converter<T>::checkJson(getVariant());
+}
+
+template <typename TDerived>
+template <typename T>
+inline bool VariantRefBase<TDerived>::set(const T& value) const {
+  Converter<T>::toJson(value, getOrCreateVariant());
+  MemoryPool* pool = getPool();
+  return pool && !pool->overflowed();
+}
+
+template <typename TDerived>
+template <typename T>
+inline bool VariantRefBase<TDerived>::set(T* value) const {
+  Converter<T*>::toJson(value, getOrCreateVariant());
+  MemoryPool* pool = getPool();
+  return pool && !pool->overflowed();
+}
+
 template <typename TDerived>
 template <typename T>
 inline typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type

+ 4 - 16
src/ArduinoJson/Variant/VariantRefBase.hpp

@@ -57,9 +57,7 @@ class VariantRefBase : public VariantTag {
   // https://arduinojson.org/v6/api/jsonvariant/as/
   template <typename T>
   FORCE_INLINE typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
-  as() const {
-    return Converter<T>::fromJson(getVariant());
-  }
+  as() const;
 
   template <typename T,
             typename = typename enable_if<!is_same<T, TDerived>::value>::type>
@@ -92,9 +90,7 @@ class VariantRefBase : public VariantTag {
   template <typename T>
   FORCE_INLINE
       typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
-      is() const {
-    return Converter<T>::checkJson(getVariant());
-  }
+      is() const;
 
   // Returns true if the value is of the specified type.
   // https://arduinojson.org/v6/api/jsonvariant/is/
@@ -123,20 +119,12 @@ class VariantRefBase : public VariantTag {
   // Copies the specified value.
   // https://arduinojson.org/v6/api/jsonvariant/set/
   template <typename T>
-  FORCE_INLINE bool set(const T& value) const {
-    Converter<T>::toJson(value, getOrCreateVariant());
-    MemoryPool* pool = getPool();
-    return pool && !pool->overflowed();
-  }
+  FORCE_INLINE bool set(const T& value) const;
 
   // Copies the specified value.
   // https://arduinojson.org/v6/api/jsonvariant/set/
   template <typename T>
-  FORCE_INLINE bool set(T* value) const {
-    Converter<T*>::toJson(value, getOrCreateVariant());
-    MemoryPool* pool = getPool();
-    return pool && !pool->overflowed();
-  }
+  FORCE_INLINE bool set(T* value) const;
 
   // Returns the size of the array or object.
   // https://arduinojson.org/v6/api/jsonvariant/size/