mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Add a constructor to VariantData
				
					
				
			This commit is contained in:
		| @@ -5,6 +5,11 @@ | |||||||
| #include <ArduinoJson.h> | #include <ArduinoJson.h> | ||||||
| #include <catch.hpp> | #include <catch.hpp> | ||||||
|  |  | ||||||
|  | TEST_CASE("VariantData") { | ||||||
|  |   REQUIRE(std::is_standard_layout<ArduinoJson::detail::VariantData>::value == | ||||||
|  |           true); | ||||||
|  | } | ||||||
|  |  | ||||||
| TEST_CASE("JsonVariant from JsonArray") { | TEST_CASE("JsonVariant from JsonArray") { | ||||||
|   SECTION("JsonArray is null") { |   SECTION("JsonArray is null") { | ||||||
|     JsonArray arr; |     JsonArray arr; | ||||||
|   | |||||||
| @@ -10,8 +10,6 @@ using namespace ArduinoJson::detail; | |||||||
|  |  | ||||||
| TEST_CASE("Test unsigned integer overflow") { | TEST_CASE("Test unsigned integer overflow") { | ||||||
|   VariantData first, second; |   VariantData first, second; | ||||||
|   first.init(); |  | ||||||
|   second.init(); |  | ||||||
|  |  | ||||||
|   // Avoids MSVC warning C4127 (conditional expression is constant) |   // Avoids MSVC warning C4127 (conditional expression is constant) | ||||||
|   size_t integerSize = sizeof(JsonInteger); |   size_t integerSize = sizeof(JsonInteger); | ||||||
| @@ -30,8 +28,6 @@ TEST_CASE("Test unsigned integer overflow") { | |||||||
|  |  | ||||||
| TEST_CASE("Test signed integer overflow") { | TEST_CASE("Test signed integer overflow") { | ||||||
|   VariantData first, second; |   VariantData first, second; | ||||||
|   first.init(); |  | ||||||
|   second.init(); |  | ||||||
|  |  | ||||||
|   // Avoids MSVC warning C4127 (conditional expression is constant) |   // Avoids MSVC warning C4127 (conditional expression is constant) | ||||||
|   size_t integerSize = sizeof(JsonInteger); |   size_t integerSize = sizeof(JsonInteger); | ||||||
| @@ -50,7 +46,6 @@ TEST_CASE("Test signed integer overflow") { | |||||||
|  |  | ||||||
| TEST_CASE("Invalid value") { | TEST_CASE("Invalid value") { | ||||||
|   VariantData result; |   VariantData result; | ||||||
|   result.init(); |  | ||||||
|  |  | ||||||
|   parseNumber("6a3", result); |   parseNumber("6a3", result); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,7 +41,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> { | |||||||
|   // https://arduinojson.org/v6/api/jsondocument/clear/ |   // https://arduinojson.org/v6/api/jsondocument/clear/ | ||||||
|   void clear() { |   void clear() { | ||||||
|     _pool.clear(); |     _pool.clear(); | ||||||
|     _data.init(); |     _data.setNull(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Returns true if the root is of the specified type. |   // Returns true if the root is of the specified type. | ||||||
| @@ -277,17 +277,11 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   JsonDocument() : _pool(0, 0) { |   JsonDocument() : _pool(0, 0) {} | ||||||
|     _data.init(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   JsonDocument(detail::MemoryPool pool) : _pool(pool) { |   JsonDocument(detail::MemoryPool pool) : _pool(pool) {} | ||||||
|     _data.init(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   JsonDocument(char* buf, size_t capa) : _pool(buf, capa) { |   JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {} | ||||||
|     _data.init(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   ~JsonDocument() {} |   ~JsonDocument() {} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -146,7 +146,6 @@ inline bool parseNumber(const char* s, VariantData& result) { | |||||||
| template <typename T> | template <typename T> | ||||||
| inline T parseNumber(const char* s) { | inline T parseNumber(const char* s) { | ||||||
|   VariantData value; |   VariantData value; | ||||||
|   value.init();  // VariantData is a POD, so it has no constructor |  | ||||||
|   parseNumber(s, value); |   parseNumber(s, value); | ||||||
|   return Converter<T>::fromJson(JsonVariantConst(&value)); |   return Converter<T>::fromJson(JsonVariantConst(&value)); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,16 +11,6 @@ | |||||||
| #include <ArduinoJson/Strings/StringAdapters.hpp> | #include <ArduinoJson/Strings/StringAdapters.hpp> | ||||||
| #include <ArduinoJson/Variant/VariantContent.hpp> | #include <ArduinoJson/Variant/VariantContent.hpp> | ||||||
|  |  | ||||||
| // VariantData can't have a constructor (to be a POD), so we have no way to fix |  | ||||||
| // this warning |  | ||||||
| #if defined(__GNUC__) |  | ||||||
| #  if __GNUC__ >= 7 |  | ||||||
| #    pragma GCC diagnostic push |  | ||||||
| #    pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |  | ||||||
| #    pragma GCC diagnostic ignored "-Wuninitialized" |  | ||||||
| #  endif |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE | ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE | ||||||
|  |  | ||||||
| class VariantData { | class VariantData { | ||||||
| @@ -28,14 +18,7 @@ class VariantData { | |||||||
|   uint8_t _flags; |   uint8_t _flags; | ||||||
|  |  | ||||||
|  public: |  public: | ||||||
|   // Must be a POD! |   VariantData() : _flags(VALUE_IS_NULL) {} | ||||||
|   // - no constructor |  | ||||||
|   // - no destructor |  | ||||||
|   // - no virtual |  | ||||||
|   // - no inheritance |  | ||||||
|   void init() { |  | ||||||
|     _flags = VALUE_IS_NULL; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void operator=(const VariantData& src) { |   void operator=(const VariantData& src) { | ||||||
|     _content = src._content; |     _content = src._content; | ||||||
| @@ -337,9 +320,3 @@ class VariantData { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| ARDUINOJSON_END_PRIVATE_NAMESPACE | ARDUINOJSON_END_PRIVATE_NAMESPACE | ||||||
|  |  | ||||||
| #if defined(__GNUC__) |  | ||||||
| #  if __GNUC__ >= 8 |  | ||||||
| #    pragma GCC diagnostic pop |  | ||||||
| #  endif |  | ||||||
| #endif |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user