From bb3d6f96af6928a8ad6841b2ea5191701ed5710c 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 Change-Id: I6818d78a57394e37857bfffd17bd69bb692dd03b Reviewed-by: Alexey Edelev (cherry picked from commit 5401a9a6cd3263eda15911c3fbfc81ebea2e798f) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 9ffed81b159e9bdf4aba26dfdbd08ff508ffe8b3) (cherry picked from commit 1e11f8fa80e5bbce11d0dfe7213d8af1e8c10fe3) --- 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 42627e22dfb..95fd4555573 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -265,7 +265,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 IfIsNotSame = diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h index 916370c3773..646c46dde24 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 >(); @@ -468,6 +470,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 aecc958536b..1c9f16ccfeb 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -475,6 +475,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}"