tst_QMetaType: fix warning that buffer may be unused

We pass a pointer to uninitialized memory to QMetaType::create().
There's no harm because we're using the invalid QMetaType, but GCC is
actually right to complain for any other type.

qtestcase.h:54:25: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
qmetatype.h:454:11: note: by argument 2 of type ‘const void*’ to ‘void* QMetaType::create(const void*) const’ declared here

Change-Id: I3859764fed084846bcb0fffd1703eb7967acf0d7
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit f1457b7b4742a3903b441d04c12cf500038f80b8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2022-07-21 11:24:17 -07:00 committed by Qt Cherry-pick Bot
parent b36803316f
commit edd3c0e6a7

View File

@ -815,7 +815,7 @@ void tst_QMetaType::createCopy()
switch (type) {
case QMetaType::UnknownType:
return []() {
char buf[1];
char buf[1] = {};
QCOMPARE(QMetaType().create(&buf), nullptr);
};
#define RETURN_CREATE_COPY_FUNCTION(MetaTypeName, MetaTypeId, RealType) \
@ -1328,7 +1328,7 @@ void tst_QMetaType::constructCopy()
switch (type) {
case QMetaType::UnknownType:
return []() {
char buf[1], buf2[1];
char buf[1], buf2[1] = {};
QCOMPARE(QMetaType().construct(&buf, &buf2), nullptr);
};
#define RETURN_CONSTRUCT_COPY_FUNCTION(MetaTypeName, MetaTypeId, RealType) \