Commit fa5963a2 authored by Philipp A Hartmann's avatar Philipp A Hartmann Committed by Philipp A Hartmann

Fix -Wclass-memaccess warnings/errors

Recent GCC versions warn about using memcpy/memmove to
write to a class pointer (-Wclass-memaccess).

Avoid the warnings by casting to void* first.

Closes #1086.
Closes #1205.
Closes #1246.
parent 4b4583bd
......@@ -1513,7 +1513,7 @@ public:
MemberIterator pos = MemberBegin() + (first - MemberBegin());
for (MemberIterator itr = pos; itr != last; ++itr)
itr->~Member();
std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
std::memmove(static_cast<void*>(&*pos), &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
data_.o.size -= static_cast<SizeType>(last - first);
return pos;
}
......@@ -1716,8 +1716,8 @@ public:
RAPIDJSON_ASSERT(last <= End());
ValueIterator pos = Begin() + (first - Begin());
for (ValueIterator itr = pos; itr != last; ++itr)
itr->~GenericValue();
std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
itr->~GenericValue();
std::memmove(static_cast<void*>(pos), last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
data_.a.size -= static_cast<SizeType>(last - first);
return pos;
}
......@@ -2032,12 +2032,7 @@ private:
if (count) {
GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
SetElementsPointer(e);
RAPIDJSON_DIAG_PUSH
#if defined(__GNUC__) && __GNUC__ >= 8
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
#endif
std::memcpy(e, values, count * sizeof(GenericValue));
RAPIDJSON_DIAG_POP
std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
}
else
SetElementsPointer(0);
......@@ -2050,12 +2045,7 @@ RAPIDJSON_DIAG_POP
if (count) {
Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
SetMembersPointer(m);
RAPIDJSON_DIAG_PUSH
#if defined(__GNUC__) && __GNUC__ >= 8
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
#endif
std::memcpy(m, members, count * sizeof(Member));
RAPIDJSON_DIAG_POP
std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
}
else
SetMembersPointer(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment