Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-96257

Cannot declare MetaType for a recursive QSet with deleted operator==

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Won't Do
    • Affects Version/s: 6.1, 6.2
    • Fix Version/s: None
    • Labels:
      None

      Description

      The following code does not compile in Qt 6:

      struct NoCmpRecursiveSet : public QSet<NoCmpRecursiveSet>
      {
          // Works if this line is removed
          bool operator==(const NoCmpRecursiveSet &) const = delete;
      };
      uint qHash(const NoCmpRecursiveSet &) { return 0; }
      
      Q_DECLARE_METATYPE(NoCmpRecursiveSet);
      

      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 = NoCmpRecursiveSet]’:
      ../../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<NoCmpRecursiveSet, QHashDummyValue>; QHashPrivate::Data<Node>::iterator = QHashPrivate::iterator<QHashPrivate::Node<NoCmpRecursiveSet, QHashDummyValue> >; QHashPrivate::Data<Node>::Key = NoCmpRecursiveSet]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:634:23:   required from ‘QHashPrivate::Data<Node>::InsertionResult QHashPrivate::Data<Node>::findOrInsert(const Key&) [with Node = QHashPrivate::Node<NoCmpRecursiveSet, QHashDummyValue>; QHashPrivate::Data<Node>::Key = NoCmpRecursiveSet]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:1179:14:   required from ‘QHash<Key, T>::iterator QHash<Key, T>::emplace(Key&&, Args&& ...) [with Args = {const QHashDummyValue&}; Key = NoCmpRecursiveSet; T = QHashDummyValue]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:1171:68:   required from ‘QHash<Key, T>::iterator QHash<Key, T>::emplace(const Key&, Args&& ...) [with Args = {const QHashDummyValue&}; Key = NoCmpRecursiveSet; T = QHashDummyValue]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhash.h:1149:34:   required from ‘QHash<Key, T>::iterator QHash<Key, T>::insert(const Key&, const T&) [with Key = NoCmpRecursiveSet; T = QHashDummyValue]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qset.h:187:56:   [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/serialization/qdatastream.h:449:45:   required from ‘QDataStreamIfHasIStreamOperatorsContainer<QSet<T>, T> operator>>(QDataStream&, QSet<T>&) [with T = NoCmpRecursiveSet; QDataStreamIfHasIStreamOperatorsContainer<QSet<T>, T> = QDataStream&]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2261:10:   required from ‘static void QtPrivate::QDataStreamOperatorForType<T, <anonymous> >::dataStreamIn(const QtPrivate::QMetaTypeInterface*, QDataStream&, void*) [with T = NoCmpRecursiveSet; 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<NoCmpRecursiveSet>::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 = NoCmpRecursiveSet]’
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/kernel/qmetatype.h:2476:61:   required from ‘int qRegisterNormalizedMetaType(const QByteArray&) [with T = NoCmpRecursiveSet]’
      ../untitled/main.cpp:145:1:   required from here
      ../../cmake-build/qtbase/include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qhashfunctions.h:209:14: error: use of deleted function ‘bool NoCmpRecursiveSet::operator==(const NoCmpRecursiveSet&) const’
        209 |     return a == b;
            |            ~~^~~~
      ../untitled/main.cpp:142:10: note: declared here
        142 |     bool operator==(const NoCmpRecursiveSet &) const = delete;
            |          ^~~~~~~~
      

      Note, that removing the explicitly deleted operator== fixes the compilation error.

      Might be related to QTBUG-96256.

      See also tst_collections.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              sonakur Sona Kurazyan
              Reporter:
              sonakur Sona Kurazyan
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes