summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-11-26 16:31:59 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-11-29 18:55:10 +0000
commitccaeffe5655cba23b4f708ec575e34f03cf08a1c (patch)
tree428371a2b2822c61b634ed61a5390d1bc32b6779 /tests/auto
parent95ccdfa43276652f1b9ca5944a94b7e15c510dbd (diff)
QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH: use unqualified qHash() lookup
... instead of QT_PREPEND_NAMESPACE(qHash), which is qualified (prepends at least '::'), and therefore disables ADL. This is not a problem as long as we wrote our qHash() overloads as free functions (incl. non-hidden friends), but it should™ fail for hidden friends, so use the old using-std::swap() trick to bring QT_PREPEND_NAMESPACE(qHash) into scope, proceeding with an unqualified lookup. Pick-to: 6.2 Change-Id: I00860b2313699849f86bfe3dd9f41db4ce993cd3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index 86305b101f..3281c4cefd 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -303,9 +303,35 @@ void tst_QHashFunctions::rangeCommutative()
}
}
+// QVarLengthArray these days has a qHash() as a hidden friend.
+// This checks that QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH can deal with that:
+
+QT_BEGIN_NAMESPACE
+QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(QVarLengthArray<QVector<int>>)
+QT_END_NAMESPACE
+
void tst_QHashFunctions::stdHash()
{
{
+ std::unordered_set<QVarLengthArray<QVector<int>>> s = {
+ {
+ {0, 1, 2},
+ {42, 43, 44},
+ {},
+ }, {
+ {11, 12, 13},
+ {},
+ },
+ };
+ QCOMPARE(s.size(), 2UL);
+ s.insert({
+ {11, 12, 13},
+ {},
+ });
+ QCOMPARE(s.size(), 2UL);
+ }
+
+ {
std::unordered_set<QString> s = {QStringLiteral("Hello"), QStringLiteral("World")};
QCOMPARE(s.size(), 2UL);
s.insert(QStringLiteral("Hello"));