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

#including <QKeySequence> before <QSet> can silently break hashes used for set comparison

    XMLWordPrintable

Details

    • fb4bc5fa26 (qt/qtbase/dev) fb4bc5fa26 (qt/tqtc-qtbase/dev), b2f3af4db (6.4)

    Description

      See attached project.

       

      Code

      // SetLib.h, part of DLL
      namespace NS
      {
          enum MyEnum
          {
              Alpha,
              Bravo,
              Charlie
          };
      
          QSet<MyEnum> QSETLIB_EXPORT getSet(); // Exported by library
          inline QSet<MyEnum> getSetInline() { return QSet<MyEnum>{Alpha}; } // NOT exported by library
      }
      
      // SetLib.cpp, part of DLL
      #include <QKeySequence>
      #include "QSetLib.h"
      
      QSet<NS::MyEnum> NS::getSet()
      {
          return QSet<MyEnum>{Alpha};
      }
      
      // main.cpp, in app that loads DLL
      #include "QSetLib.h"
      #include <QDebug>
      
      int main()
      {
          auto set1 = NS::getSet();
          auto set2 = NS::getSetInline();
      
          qDebug() << "Set contents are equal?" << (set1.values() == set2.values());
          qDebug() << "Sets are equal?" << (set1 == set2);
      }
      

       

      Qt 5.15.11 output (Correct)

      Set contents are equal? true
      Sets are equal? true
      

       

      Qt 6.2.6/6.4.0 output (Wrong)

      Set contents are equal? true
      Sets are equal? false
      

       

      Notes

      You can replace #include <QKeySequence> with the following and still trigger the error:

      struct Conflictor { Conflictor(int); };
      size_t qHash(const Conflictor &key, size_t seed = 0) noexcept;
      

       

      Workarounds

      • Make sure that <QSet> is included before <QKeySequence>, OR
      • Convert the enum to an enum class, to prevent implicit conversion to int

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-108032
          # Subject Branch Project Status CR V

          Activity

            People

              thiago Thiago Macieira
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are 2 open Gerrit changes