Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
6.2.0 RC, 6.2.0
-
None
-
-
01d94760d8d34e51e1442682fc151747943c7e25 (qt/qtbase/dev) f92df090f5879531534b085dcc6dd96cc0e692da (qt/qtbase/6.2) f887a8eab25fd2cf3beee7527198f41ac15c8fcd (qt/qtbase/6.2.0)
Description
QMetaObject found the operator< in the std::optional and tries to compile it. But std::optional requires it's value_type to also contain operator<, so compilation fails because compiler unable to find operator< in value_type.
Simple example:
#pragma once #include <QObject> #include <optional> struct SimpleStruct { int a = 42; }; class TestClass : public QObject { Q_OBJECT public: explicit TestClass(QObject *parent = nullptr); signals: void test(const std::optional<SimpleStruct> &opt); };
Full example: Qt6OptionalBug.zip
Compile output:
[1/4 4.9/sec] Automatic MOC and UIC for target Qt6OptionalBug [2/4 1.5/sec] Building CXX object CMakeFiles\Qt6OptionalBug.dir\Qt6OptionalBug_autogen\mocs_compilation.cpp.obj FAILED: CMakeFiles/Qt6OptionalBug.dir/Qt6OptionalBug_autogen/mocs_compilation.cpp.obj C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\cl.exe /nologo /TP -DQT_CORE_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -ID:\workspace\build-Qt6OptionalBug-Desktop_Qt_6_2_0_MSVC2019_64bit-Debug -ID:\workspace\Qt6OptionalBug -ID:\workspace\build-Qt6OptionalBug-Desktop_Qt_6_2_0_MSVC2019_64bit-Debug\Qt6OptionalBug_autogen\include -ID:\Qt\6.2.0\msvc2019_64\include\QtCore -ID:\Qt\6.2.0\msvc2019_64\include -ID:\Qt\6.2.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\Qt6OptionalBug.dir\Qt6OptionalBug_autogen\mocs_compilation.cpp.obj /FdCMakeFiles\Qt6OptionalBug.dir\ /FS -c D:\workspace\build-Qt6OptionalBug-Desktop_Qt_6_2_0_MSVC2019_64bit-Debug\Qt6OptionalBug_autogen\mocs_compilation.cpp C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\optional(468): error C2678: binary '<': no operator found which takes a left-hand operand of type 'const _Ty' (or there is no acceptable conversion) with [ _Ty=SimpleStruct ] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\variant(1747): note: could be 'bool std::operator <(std::monostate,std::monostate) noexcept' C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\optional(468): note: while trying to match the argument list '(const _Ty, const _Ty)' with [ _Ty=SimpleStruct ] D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2219): note: see reference to function template instantiation 'bool std::operator <<SimpleStruct,SimpleStruct>(const std::optional<SimpleStruct> &,const std::optional<SimpleStruct> &)' being compiled D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2219): note: while compiling class template member function 'bool QtPrivate::QLessThanOperatorForType<T,true>::lessThan(const QtPrivate::QMetaTypeInterface *,const void *,const void *)' with [ T=Ty ] D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2344): note: see reference to function template instantiation 'bool QtPrivate::QLessThanOperatorForType<T,true>::lessThan(const QtPrivate::QMetaTypeInterface *,const void *,const void *)' being compiled with [ T=Ty ] D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2339): note: see reference to class template instantiation 'QtPrivate::QLessThanOperatorForType<T,true>' being compiled with [ T=Ty ] D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2453): note: see reference to class template instantiation 'QtPrivate::QMetaTypeInterfaceWrapper<Ty>' being compiled D:\Qt\6.2.0\msvc2019_64\include\QtCore/qmetatype.h(2496): note: see reference to function template instantiation 'const QtPrivate::QMetaTypeInterface *QtPrivate::qTryMetaTypeInterfaceForType<Unique,QtPrivate::TypeAndForceComplete<const std::optional<SimpleStruct> &,std::false_type>>(void)' being compiled with [ Unique=qt_meta_stringdata_TestClass_t ] D:\workspace\build-Qt6OptionalBug-Desktop_Qt_6_2_0_MSVC2019_64bit-Debug\Qt6OptionalBug_autogen\EWIEGA46WW/moc_testclass.cpp(93): note: see reference to variable template 'const QtPrivate::QMetaTypeInterface *const qt_incomplete_metaTypeArray<qt_meta_stringdata_TestClass_t,QtPrivate::TypeAndForceComplete<TestClass,std::integral_constant<bool,1> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<std::optional<SimpleStruct> const &,std::integral_constant<bool,0> > >[3]' being compiled [3/4 2.3/sec] Building CXX object CMakeFiles\Qt6OptionalBug.dir\testclass.cpp.obj ninja: build stopped: subcommand failed. 13:46:21: The process "D:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 1. Error while building/deploying project Qt6OptionalBug (kit: Desktop Qt 6.2.0 MSVC2019 64bit) When executing step "Build"