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

Using copy-restricted class in lambda for QFuture's then(), does not build

    XMLWordPrintable

    Details

    • Platform/s:
      Linux/X11, Windows
    • Commits:
      d82671a149cdc3f46de498193967d3c4d677923e (qt/qtbase/6.2) 3be72253a6 (qt/tqtc-qtbase/6.3)

      Description

      When using QFuture's continuation (then()) with a lambda that tries to capture an instance of a class through copy, it does not work if that class has deleted copy construction.

      I.e.:

      QPromise<QNetworkReply*> promise;
      test2(request).then([promise=std::move(promise)](QNetworkReply* networkReply) { });
      

      If the class does not delete copy construction, this works. Also as a workaround, using QSharedPointer or allocating the promise to heap builds successfully.

      Mingw build log of the failure (it's clearer than MSVC output, that is attached):

      12:49:47: Running steps for project qtbug...
      12:49:47: Starting: "C:\Qt\Tools\CMake_64\bin\cmake.exe" --build C:/build-qtbug-Desktop_Qt_6_2_0_MinGW_64_bit-Debug --target all
      [1/2 0.7/sec] Building CXX object CMakeFiles/qtbug.dir/main.cpp.obj
      FAILED: CMakeFiles/qtbug.dir/main.cpp.obj 
      C:\Qt\Tools\mingw810_64\bin\g++.exe -DMINGW_HAS_SECURE_API=1 -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_NETWORK_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN32_WINNT=0x0601 -D_WIN64 -IC:/build-qtbug-Desktop_Qt_6_2_0_MinGW_64_bit-Debug/qtbug_autogen/include -IC:/qtbug -isystem C:/Qt/6.2.0/mingw81_64/include/QtCore -isystem C:/Qt/6.2.0/mingw81_64/include -isystem C:/Qt/6.2.0/mingw81_64/mkspecs/win32-g++ -isystem C:/Qt/6.2.0/mingw81_64/include/QtConcurrent -isystem C:/Qt/6.2.0/mingw81_64/include/QtNetwork -g -Wno-error=invalid-offsetof -std=gnu++17 -MD -MT CMakeFiles/qtbug.dir/main.cpp.obj -MF CMakeFiles\qtbug.dir\main.cpp.obj.d -o CMakeFiles/qtbug.dir/main.cpp.obj -c C:/qtbug/main.cpp
      In file included from C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/functional:59,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/qchar.h:45,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/qstring.h:50,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/qcoreapplication.h:44,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/QCoreApplication:1,
                       from C:/qtbug/main.cpp:1:
      C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/std_function.h: In instantiation of 'static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::false_type) [with _Functor = QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>; std::false_type = std::integral_constant<bool, false>]':
      C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/std_function.h:208:16:   required from 'static bool std::_Function_base::_Base_manager<_Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Functor = QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>]'
      C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/std_function.h:676:19:   required from 'std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>; <template-parameter-2-2> = void; <template-parameter-2-3> = void; _Res = void; _ArgTypes = {const QFutureInterfaceBase&}]'
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture_impl.h:501:5:   required from 'static void QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]'
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture.h:358:85:   required from 'QFuture<typename QtPrivate::ResultTypeHelper<Function, T>::ResultType> QFuture<T>::then(QtFuture::Launch, Function&&) [with Function = test()::<lambda(QNetworkReply*)>; T = QNetworkReply*; typename QtPrivate::ResultTypeHelper<Function, T>::ResultType = void]'
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture.h:349:73:   required from 'QFuture<typename QtPrivate::ResultTypeHelper<Function, T>::ResultType> QFuture<T>::then(Function&&) [with Function = test()::<lambda(QNetworkReply*)>; T = QNetworkReply*; typename QtPrivate::ResultTypeHelper<Function, T>::ResultType = void]'
      C:/qtbug/main.cpp:27:86:   required from here
      C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/std_function.h:173:6: error: use of deleted function 'QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>::<lambda>(const QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>&)'
            new _Functor(*__source._M_access<_Functor*>());
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      In file included from C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture.h:48,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/qcoreapplication.h:49,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/QCoreApplication:1,
                       from C:/qtbug/main.cpp:1:
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture_impl.h:479:10: note: 'QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>::<lambda>(const QtPrivate::Continuation<Function, ResultType, ParentResultType>::create(F&&, QFuture<ParentResultType>*, QFutureInterface<ResultType>&, QtFuture::Launch) [with F = test()::<lambda(QNetworkReply*)>; Function = test()::<lambda(QNetworkReply*)>; ResultType = void; ParentResultType = QNetworkReply*]::<lambda(const QFutureInterfaceBase&)>&)' is implicitly deleted because the default definition would be ill-formed:
           auto continuation = [func = std::forward<F>(func), p, pool,
                ^~~~~~~~~~~~
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture_impl.h:479:10: error: use of deleted function 'test()::<lambda(QNetworkReply*)>::<lambda>(const test()::<lambda(QNetworkReply*)>&)'
      C:/qtbug/main.cpp:27:52: note: 'test()::<lambda(QNetworkReply*)>::<lambda>(const test()::<lambda(QNetworkReply*)>&)' is implicitly deleted because the default definition would be ill-formed:
           test2(request).then([promise=std::move(promise)](QNetworkReply* networkReply) { });
                                                          ^
      C:/qtbug/main.cpp:27:52: error: use of deleted function 'QPromise<T>::QPromise(const QPromise<T>&) [with T = QNetworkReply*]'
      In file included from C:/Qt/6.2.0/mingw81_64/include/QtCore/qcoreapplication.h:43,
                       from C:/Qt/6.2.0/mingw81_64/include/QtCore/QCoreApplication:1,
                       from C:/qtbug/main.cpp:1:
      C:/Qt/6.2.0/mingw81_64/include/QtCore/qpromise.h:60:5: note: declared here
           Q_DISABLE_COPY(QPromise)
           ^~~~~~~~~~~~~~
      ninja: build stopped: subcommand failed.
      12:49:49: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 1.
      Error while building/deploying project qtbug (kit: Desktop Qt 6.2.0 MinGW 64-bit)
      When executing step "Build"
      12:49:49: Elapsed time: 00:02.
      

        Attachments

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

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes