Silence GCC 8 warning on memcpy of class Value to to class offset

From GCC 8:

error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of type ‘QJsonPrivate::offset’ {aka ‘class QSpecialInteger<QLittleEndianStorageType<unsigned int> >’} with ‘private’ member ‘QSpecialInteger<QLittleEndianStorageType<unsigned int> >::val’
from an array of ‘const value_type’ {aka ‘const class QJsonPrivate::Value’}; use assignment or copy-initialization instead [-Werror=class-memaccess]

Both types are standard layout and have the same initial sequence (one uint
member), so this is a valid copy. The only difference between the two is that
QSpecialInteger has a private member, whereas in the bitfield it's public.

Change-Id: I41d006aac5bc48529845fffd150e80585fd24db7
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2018-01-29 21:46:40 -08:00
parent b7e4367387
commit 1514b4e853

View File

@ -297,7 +297,8 @@ QJsonArray QJsonArray::fromVariantList(const QVariantList &list)
array.a->tableOffset = currentOffset;
if (!array.detach2(sizeof(QJsonPrivate::offset)*values.size()))
return QJsonArray();
memcpy(array.a->table(), values.constData(), values.size()*sizeof(uint));
memcpy(static_cast<void *>(array.a->table()),
static_cast<const void *>(values.constData()), values.size()*sizeof(uint));
array.a->length = values.size();
array.a->size = currentOffset + sizeof(QJsonPrivate::offset)*values.size();