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