From 528c78d3a21eeba6efa03a401d5b49e816a0bd58 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 3 Dec 2024 13:33:51 +0100 Subject: [PATCH] tst_collections.cpp: fix RecursiveList comparison case The RecursiveList structure was defined like this: struct RecursiveList : public QList {}; However, this definition does not make any sense when it comes to the relational operators. QList needs to have operator<() defined for the contained type T. The current implementation of QTypeTraits::compare_lt_result_container simply enables operator<() if Container is a base type of the contained type. This unblocks the compilation of checks like static_assert(QTypeTraits::has_operator_less_than_v); However, this is useless in practice. This commit updates the struct to have a meaningful definition of operator<(). Amends 9f13842fe61541cb8ab9822174ea963e418b5537. Task-number: QTBUG-120305 Pick-to: 6.5 Change-Id: Iaee96385a33ff131bdceabe945265b3285a370c2 Reviewed-by: Marc Mutz (cherry picked from commit 58c492a4dc9868faff7e9334758947cf0027eeac) Reviewed-by: Qt Cherry-pick Bot --- .../auto/corelib/tools/collections/tst_collections.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 5e3313b474b..1aded0b4409 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -155,7 +155,15 @@ struct Dummy bool operator<(const Dummy &) const { return false; } }; -struct RecursiveList : public QList {}; +struct RecursiveList : public QList +{ + friend bool operator<(const RecursiveList &lhs, const RecursiveList &rhs) + { + using Base = QList; + // compare some non-QList members here + return static_cast(lhs) < static_cast(rhs); + } +}; struct RecursiveSet : public QSet {}; struct RecursiveMapV : public QMap {}; struct RecursiveMapK : public QMap {};