From 30735ba187ef0a7918e7e0e37a3ef465f8c4dca5 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 20 Mar 2021 00:12:36 +0100 Subject: [PATCH] Fix warnings --- lib/json/reflector.h | 18 ++++++------------ lib/tests/jsonreflector-boosthana.cpp | 10 +++++----- lib/tests/jsonreflector.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/json/reflector.h b/lib/json/reflector.h index 7d7cb63..43dbe00 100644 --- a/lib/json/reflector.h +++ b/lib/json/reflector.h @@ -206,7 +206,7 @@ void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_ { value.SetArray(); RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray()); - array.Reserve(reflectable.size(), allocator); + array.Reserve(rapidJsonSize(reflectable.size()), allocator); for (const auto &item : reflectable) { push(item, array, allocator); } @@ -332,7 +332,7 @@ void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_ } RAPIDJSON_NAMESPACE::Value index, data; - index.SetInt(reflectable.index()); + index.SetUint64(reflectable.index()); std::visit( [&data, &allocator](const auto &reflectableOfActualType) { if constexpr (!std::is_same_v, std::monostate>) { @@ -745,9 +745,9 @@ void pull(Type &reflectable, const rapidjson::GenericValuevalue.GetArray(); - for (const auto &value : array) { + for (const auto &arrayValue : array) { auto insertedIterator = reflectable.insert(typename Type::value_type(i->name.GetString(), typename Type::mapped_type())); - pull(insertedIterator->second, value, errors); + pull(insertedIterator->second, arrayValue, errors); } } } @@ -899,20 +899,14 @@ void pull(Type &reflectable, const rapidjson::GenericValuevalue; - if (!indexValue.IsInt()) { + if (!indexValue.IsUint64()) { if (errors) { errors->emplace_back(JsonDeserializationErrorKind::InvalidVariantIndex, JsonType::Number, jsonType(indexValue.GetType()), errors->currentRecord, errors->currentMember, errors->currentIndex); } return; } - const auto index = indexValue.GetInt(); - if (index < 0) { - errors->emplace_back(JsonDeserializationErrorKind::InvalidVariantIndex, JsonType::Number, JsonType::Number, errors->currentRecord, - errors->currentMember, errors->currentIndex); - return; - } - Detail::assignVariantValueByRuntimeIndex(static_cast(index), reflectable, dataIterator->value, errors); + Detail::assignVariantValueByRuntimeIndex(indexValue.GetUint64(), reflectable, dataIterator->value, errors); } /*! diff --git a/lib/tests/jsonreflector-boosthana.cpp b/lib/tests/jsonreflector-boosthana.cpp index 7b5ede0..988cf7c 100644 --- a/lib/tests/jsonreflector-boosthana.cpp +++ b/lib/tests/jsonreflector-boosthana.cpp @@ -160,11 +160,11 @@ void JsonReflectorBoostHanaTests::testDeserializeNestedObjects() CPPUNIT_ASSERT_EQUAL(2_st, testObjects.size()); CPPUNIT_ASSERT_EQUAL(42, testObjects[0].number); CPPUNIT_ASSERT_EQUAL(43, testObjects[1].number); - for (const TestObjectHana &testObj : testObjects) { - CPPUNIT_ASSERT_EQUAL(3.141592653589793, testObj.number2); - CPPUNIT_ASSERT_EQUAL(vector({ 1, 2, 3, 4 }), testObj.numbers); - CPPUNIT_ASSERT_EQUAL("test"s, testObj.text); - CPPUNIT_ASSERT_EQUAL(false, testObj.boolean); + for (const TestObjectHana &nestedTestObj : testObjects) { + CPPUNIT_ASSERT_EQUAL(3.141592653589793, nestedTestObj.number2); + CPPUNIT_ASSERT_EQUAL(vector({ 1, 2, 3, 4 }), nestedTestObj.numbers); + CPPUNIT_ASSERT_EQUAL("test"s, nestedTestObj.text); + CPPUNIT_ASSERT_EQUAL(false, nestedTestObj.boolean); } } diff --git a/lib/tests/jsonreflector.cpp b/lib/tests/jsonreflector.cpp index 8414f24..c016e99 100644 --- a/lib/tests/jsonreflector.cpp +++ b/lib/tests/jsonreflector.cpp @@ -500,11 +500,11 @@ void JsonReflectorTests::testDeserializeNestedObjects() CPPUNIT_ASSERT_EQUAL(2_st, testObjects.size()); CPPUNIT_ASSERT_EQUAL(42, testObjects[0].number); CPPUNIT_ASSERT_EQUAL(43, testObjects[1].number); - for (const TestObject &testObj : testObjects) { - CPPUNIT_ASSERT_EQUAL(3.141592653589793, testObj.number2); - CPPUNIT_ASSERT_EQUAL(vector({ 1, 2, 3, 4 }), testObj.numbers); - CPPUNIT_ASSERT_EQUAL("test"s, testObj.text); - CPPUNIT_ASSERT_EQUAL(false, testObj.boolean); + for (const TestObject &nestedTestObj : testObjects) { + CPPUNIT_ASSERT_EQUAL(3.141592653589793, nestedTestObj.number2); + CPPUNIT_ASSERT_EQUAL(vector({ 1, 2, 3, 4 }), nestedTestObj.numbers); + CPPUNIT_ASSERT_EQUAL("test"s, nestedTestObj.text); + CPPUNIT_ASSERT_EQUAL(false, nestedTestObj.boolean); } const auto nestedInVector(JsonReflector::fromJson>(