QVariant: remove UB and fix semantics in a test
The code was reading from uninitialized memory when creating a variant. Fixing that reveals that the test semantics are broken: when dealing with datatypes without a registered operator==, QVariant resorts to memcmp, so the two objects would've actually compared equal. Amend that. Change-Id: I36bad7ee6a45154d5d534b7dd8b618cc0a900126 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
f133b226cd
commit
c0f7ecab20
@ -2865,15 +2865,15 @@ void tst_QVariant::compareCustomTypes() const
|
||||
{
|
||||
qRegisterMetaType<WontCompare>("WontCompare");
|
||||
|
||||
WontCompare f1;
|
||||
WontCompare f1 = {};
|
||||
f1.x = 0;
|
||||
const QVariant variant1(QVariant::fromValue(f1));
|
||||
|
||||
WontCompare f2;
|
||||
f2.x = 0;
|
||||
WontCompare f2 = {};
|
||||
f2.x = 1;
|
||||
const QVariant variant2(QVariant::fromValue(f2));
|
||||
|
||||
/* We compare pointers. */
|
||||
/* We compare via memcmp. */
|
||||
QVERIFY(variant1 != variant2);
|
||||
QCOMPARE(variant1, variant1);
|
||||
QCOMPARE(variant2, variant2);
|
||||
|
Loading…
Reference in New Issue
Block a user