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

[Reg 5.15->6.0] Recursive QMap as MetaType cannot have key with custom operator==

    XMLWordPrintable

    Details

    • Platform/s:
      Windows
    • Commits:
      9f13842fe61541cb8ab9822174ea963e418b5537 (qt/qtbase/dev) ba5d797d0787276019b342fdb5b2dfb72ea6c550 (qt/qtbase/6.1) c315583a82eac39bce6feb0f5f4d4f6036b01611 (qt/qtbase/6.2)
    • Story Points:
      13
    • Sprint:
      Foundation_Sprint 41 (Team 1)

      Description

      The following code no longer compiles with MSVC (2019):

      class Input {
      public:
          bool operator==(const Input &a) const
          {
              return false;
          }
          bool operator!=(const Input &a) const { return !(*this == a); }
      };
      
      class ModeMapping : public QMap<Input, ModeMapping>
      {
      };
      
      Q_DECLARE_METATYPE(ModeMapping)
      

      This compiles with Qt 5, but no longer with Qt 6:

      C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\HostX86\x64\cl.exe  /nologo /TP -DQT_CORE_LIB -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_WIN64 -I. -IC:\Users\ziller\Documents\untitled2 -Iuntitled2_autogen\include -IC:\Qt\6.1.0\msvc2019_64\include\QtCore -IC:\Qt\6.1.0\msvc2019_64\include -IC:\Qt\6.1.0\msvc2019_64\mkspecs\win32-msvc /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1   -Zc:__cplusplus -permissive- -utf-8 -std:c++17 /showIncludes /FoCMakeFiles\untitled2.dir\main.cpp.obj /FdCMakeFiles\untitled2.dir\ /FS -c C:\Users\ziller\Documents\untitled2\main.cpp
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(54): error C2039: 'value': is not a member of 'QTypeTraits::has_operator_equal<T>'
              with
              [
                  T=Ty
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): note: see declaration of 'QTypeTraits::has_operator_equal<T>'
              with
              [
                  T=Ty
              ]
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(61): note: see reference to class template instantiation 'std::_Conjunction<true,_First,QTypeTraits::has_operator_equal<T>>' being compiled
              with
              [
                  _First=QTypeTraits::has_operator_equal<Input>,
                  T=Ty
              ]
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): note: see reference to class template instantiation 'std::conjunction<QTypeTraits::has_operator_equal<Key>,QTypeTraits::has_operator_equal<T>>' being compiled
              with
              [
                  Key=Input,
                  T=Ty
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(334): note: see reference to variable template 'const bool conjunction_v<QTypeTraits::has_operator_equal<Input>,QTypeTraits::has_operator_equal<ModeMapping> >' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmap.h(280): note: see reference to alias template instantiation 'QTypeTraits::compare_eq_result<Input,ModeMapping>' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmap.h(291): note: see reference to function template instantiation 'enable_if<std::conjunction_v<QTypeTraits::has_operator_equal<T>,QTypeTraits::has_operator_equal<AT>>,bool>::type operator !=(const QMap<Input,ModeMapping> &,const QMap<Input,ModeMapping> &)' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(324): note: see reference to alias template instantiation 'QTypeTraits::detail::expand_operator_equal<Ty>' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): note: see reference to class template instantiation 'QTypeTraits::has_operator_equal<T>' being compiled
              with
              [
                  T=Ty
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2126): note: see reference to variable template 'const bool has_operator_equal_v<ModeMapping>' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2328): note: see reference to class template instantiation 'QtPrivate::QMetaTypeInterfaceWrapper<Ty>' being compiled
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2389): note: see reference to function template instantiation 'const QtPrivate::QMetaTypeInterface *QtPrivate::qMetaTypeInterfaceForType<T>(void)' being compiled
              with
              [
                  T=ModeMapping
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(1146): note: see reference to function template instantiation 'QMetaType QMetaType::fromType<T>(void)' being compiled
              with
              [
                  T=ModeMapping
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(1170): note: see reference to function template instantiation 'int qRegisterNormalizedMetaType<T>(const QByteArray &)' being compiled
              with
              [
                  T=ModeMapping
              ]
      C:\Users\ziller\Documents\untitled2\main.cpp(18): note: see reference to function template instantiation 'int qRegisterMetaType<ModeMapping>(const char *)' being compiled
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(54): error C2065: 'value': undeclared identifier
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(54): error C2975: '_First_value': invalid template argument for 'std::_Conjunction', expected compile-time constant expression
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(47): note: see declaration of '_First_value'
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(61): error C2504: 'QTypeTraits::has_operator_equal<T>': base class undefined
              with
              [
                  T=Ty
              ]
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): error C2039: 'value': is not a member of 'std::conjunction<QTypeTraits::has_operator_equal<Key>,QTypeTraits::has_operator_equal<T>>'
              with
              [
                  Key=Input,
                  T=Ty
              ]
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): note: see declaration of 'std::conjunction<QTypeTraits::has_operator_equal<Key>,QTypeTraits::has_operator_equal<T>>'
              with
              [
                  Key=Input,
                  T=Ty
              ]
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): error C2065: 'value': undeclared identifier
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): error C2131: expression did not evaluate to a constant
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\type_traits(66): note: a non-constant (sub-)expression was encountered
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(253): error C2976: 'QTypeTraits::detail::expand_operator_equal_container': too few template arguments
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(257): note: see declaration of 'QTypeTraits::detail::expand_operator_equal_container'
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(324): error C3770: 'unknown-type': is not a valid base class
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): error C2039: 'value': is not a member of 'QTypeTraits::has_operator_equal<T>'
              with
              [
                  T=Ty
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): note: see declaration of 'QTypeTraits::has_operator_equal<T>'
              with
              [
                  T=Ty
              ]
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): error C2065: 'value': undeclared identifier
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): error C2131: expression did not evaluate to a constant
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qtypeinfo.h(326): note: a non-constant (sub-)expression was encountered
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2265): error C2976: 'QtPrivate::QEqualityOperatorForType': too few template arguments
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2128): note: see declaration of 'QtPrivate::QEqualityOperatorForType'
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2265): error C2975: 'unnamed-parameter': invalid template argument for 'QtPrivate::QEqualityOperatorForType', expected compile-time constant expression
      C:\Qt\6.1.0\msvc2019_64\include\QtCore/qmetatype.h(2126): note: see declaration of 'unnamed-parameter'
      ninja: build stopped: subcommand failed.

      Real-life example of this is "class ModeMapping : public QMap<Input, ModeMapping>" in FakeVim in Qt Creator (https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/plugins/fakevim/fakevimhandler.cpp#n1632)

        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:
              con Eike Ziller
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes