From 5401a9a6cd3263eda15911c3fbfc81ebea2e798f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 16 Mar 2024 18:41:27 -0700 Subject: [PATCH] QDBusArgument: disambiguate between QMap on std::pair and std::map For QMap on a std::pair, QMap::iterator{}.operator->() would result in a type that has "first" and "second" members: std::pair itself. But it would be wrong to marshall and demarshall the first and second elements thereof as the key and value, so give preference to the .key() and .value() selection, which would store the std::pair as the type. Fixes: QTBUG-123401 Pick-to: 6.5 6.6 6.7 Change-Id: I6818d78a57394e37857bfffd17bd69bb692dd03b Reviewed-by: Alexey Edelev --- src/corelib/tools/qcontainertools_impl.h | 6 +++++- tests/auto/dbus/qdbusmarshall/common.h | 4 ++++ tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index ef73a2a69f7..f53ab0c48da 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -309,7 +309,11 @@ using IfAssociativeIteratorHasKeyAndValue = template using IfAssociativeIteratorHasFirstAndSecond = - std::enable_if_t, bool>; + std::enable_if_t< + std::conjunction_v< + std::negation>, + qxp::is_detected + >, bool>; template using MoveBackwardsTest = decltype( diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h index a7d81960217..9a7c1e1553a 100644 --- a/tests/auto/dbus/qdbusmarshall/common.h +++ b/tests/auto/dbus/qdbusmarshall/common.h @@ -152,7 +152,9 @@ void commonInit() qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); + qDBusRegisterMetaType>>(); + qDBusRegisterMetaType>(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType >(); @@ -471,6 +473,8 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) return compare >(arg, v2); else if (id == qMetaTypeId >()) return compare >(arg, v2); + else if (id == qMetaTypeId>>()) + return compare>>(arg, v2); else if (id == qMetaTypeId >()) return compare >(arg, v2); diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index 8d61e127363..e7a82731151 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -476,6 +476,17 @@ void tst_QDBusMarshall::sendMaps_data() QTest::newRow("gs-map") << QVariant::fromValue(gsmap) << "a{gs}" << "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]"; + QMap> siimap; + QTest::newRow("empty-sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}" + << "[Argument: a{s(ii)} {}]"; + siimap["0,0"] = { 0, 0 }; + siimap["1,-1"] = { 1, -1 }; + QTest::newRow("sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}" + << "[Argument: a{s(ii)} {" + "\"0,0\" = [Argument: (ii) 0, 0], " + "\"1,-1\" = [Argument: (ii) 1, -1]" + "}]"; + if (fileDescriptorPassing) { svmap["zzfiledescriptor"] = QVariant::fromValue(QDBusUnixFileDescriptor(fileDescriptorForTest())); QTest::newRow("sv-map1-fd") << QVariant::fromValue(svmap) << "a{sv}"