Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
6.1, 6.2
-
None
-
5
-
a9d51298ae34ed05adb100983ed92bec07ce2ce5 (qt/qtbase/dev) c9c8e06189055be5597b7a108a999543d44c1e41 (qt/qtbase/6.2)
-
Team 1 Foundation_Sprint 44
Description
The following code does not compile in Qt 6:
struct Empty {}; struct NoCmpKeyHash : public QHash<Empty, int> { // Works if this is uncommented // bool operator==(const NoCmpKeyHash &) const = delete; }; uint qHash(const Empty &) { return 0; } Q_DECLARE_METATYPE(NoCmpKeyHash);
with the following output:
../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhashfunctions.h: In instantiation of ‘bool qHashEquals(const T&, const T&) [with T = Empty]’: ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:607:32: required from ‘QHashPrivate::Data<Node>::iterator QHashPrivate::Data<Node>::find(const Key&) const [with Node = QHashPrivate::Node<Empty, int>; QHashPrivate::Data<Node>::iterator = QHashPrivate::iterator<QHashPrivate::Node<Empty, int> >; QHashPrivate::Data<Node>::Key = Empty]’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:1138:14: required from ‘QHash<Key, T>::const_iterator QHash<Key, T>::find(const Key&) const [with Key = Empty; T = int]’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:831:28: required from ‘QTypeTraits::compare_eq_result_container<QHash<Key, T>, U> QHash<Key, T>::operator==(const QHash<Key, T>&) const [with U = int; Key = Empty; T = int; QTypeTraits::compare_eq_result_container<QHash<Key, T>, U> = bool]’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2219:46: required from ‘static bool QtPrivate::QEqualityOperatorForType<T, <anonymous> >::equals(const QtPrivate::QMetaTypeInterface*, const void*, const void*) [with T = NoCmpKeyHash; bool <anonymous> = true]’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2340:54: required from ‘constexpr const QtPrivate::QMetaTypeInterface QtPrivate::QMetaTypeInterfaceWrapper<NoCmpKeyHash>::metaType’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2415:12: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qMetaTypeInterfaceForType() [with T = NoCmpKeyHash]’ ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2476:61: required from ‘int qRegisterNormalizedMetaType(const QByteArray&) [with T = NoCmpKeyHash]’ ../untitled/main.cpp:146:1: required from here ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhashfunctions.h:209:14: error: no match for ‘operator==’ (operand types are ‘const Empty’ and ‘const Empty’) 209 | return a == b; | ~~^~~~
Note, that explicitly deleting the operator== of the key type fixes the compilation error.
The similar code for QMultiHash also fails in the same way.
See also tst_collections.
Attachments
Issue Links
- relates to
-
QTBUG-96257 Cannot declare MetaType for a recursive QSet with deleted operator==
-
- Closed
-
For Gerrit Dashboard: QTBUG-96256 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
377319,3 | Fix metatype declaration for QHash/QMultiHash with no operator== | dev | qt/qtbase | Status: MERGED | +2 | 0 |
377604,2 | Fix metatype declaration for QHash/QMultiHash with no operator== | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |