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

QtHttpServer::route()/afterRequest(): Compile errors when assigning the lambda to variable and passing that

    XMLWordPrintable

Details

    • Linux/X11
    • b5f8b59c70 (qt/qthttpserver/dev) 564b56ffdf (qt/qthttpserver/6.4)

    Description

      Modifying the simple example from

       httpServer.route("/query", [] (const QHttpServerRequest &request) {
              return QString("%1/query/").arg(host(request));
          });
      

      to

         auto lbda = [] (const QHttpServerRequest &request) {
              return QString("%1/query/").arg(host(request));
          };
      
          httpServer.route("/query", lbda);
      

      results in an error flood (g++ 9.4.0)

      In file included from include/QtHttpServer/qhttpserverrouterviewtraits.h:34,
                       from include/QtHttpServer/qhttpserverrouter.h:34,
                       from include/QtHttpServer/qhttpserver.h:35,
                       from include/QtHttpServer/QtHttpServer:6,
                       from main.cpp:52:
      include/QtHttpServer/qhttpserverviewtraits_impl.h: In instantiation of ‘struct QtPrivate::FunctionTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&>’:
      include/QtHttpServer/qhttpserverviewtraits_impl.h:117:11:   required from ‘struct QtPrivate::ViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’
      include/QtHttpServer/qhttpserverrouterviewtraits.h:44:8:   required from ‘struct QtPrivate::RouterViewTraitsHelper<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’
      include/QtHttpServer/qhttpserverrouterviewtraits.h:152:11:   required from ‘struct QHttpServerRouterViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’
      include/QtHttpServer/qhttpserver.h:82:46:   required from ‘bool QHttpServer::route(Args&& ...) [with Rule = QHttpServerRouterRule; Args = {const char (&)[7], main(int, char**)::<lambda(const QHttpServerRequest&)>&}]’
      main.cpp:72:36:   required from here
      include/QtHttpServer/qhttpserverviewtraits_impl.h:92:56: error: ‘operator()’ is not a member of ‘main(int, char**)::<lambda(const QHttpServerRequest&)>&’
         92 | struct FunctionTraits : public FunctionTraits<decltype(&T::operator())>{};
            |                                                        ^~~~~~~~~~~~~~
      include/QtHttpServer/qhttpserverviewtraits_impl.h: In instantiation of ‘struct QtPrivate::ViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’:
      include/QtHttpServer/qhttpserverrouterviewtraits.h:44:8:   required from ‘struct QtPrivate::RouterViewTraitsHelper<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’
      include/QtHttpServer/qhttpserverrouterviewtraits.h:152:11:   required from ‘struct QHttpServerRouterViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’
      include/QtHttpServer/qhttpserver.h:82:46:   required from ‘bool QHttpServer::route(Args&& ...) [with Rule = QHttpServerRouterRule; Args = {const char (&)[7], main(int, char**)::<lambda(const QHttpServerRequest&)>&}]’
      main.cpp:72:36:   required from here
      include/QtHttpServer/qhttpserverviewtraits_impl.h:117:11: error: ‘ArgumentCount’ is not a member of ‘QtPrivate::FunctionTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&>’
        117 |     using ArgumentIndexes = typename Indexes<FTraits::ArgumentCount>::Value;
            |           ^~~~~~~~~~~~~~~
      In file included from include/QtHttpServer/qhttpserverrouter.h:34,
                       from include/QtHttpServer/qhttpserver.h:35,
                       from include/QtHttpServer/QtHttpServer:6,
                       from main.cpp:52:
      include/QtHttpServer/qhttpserverrouterviewtraits.h: In instantiation of ‘struct QHttpServerRouterViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>’:
      include/QtHttpServer/qhttpserver.h:82:46:   required from ‘bool QHttpServer::route(Args&& ...) [with Rule = QHttpServerRouterRule; Args = {const char (&)[7], main(int, char**)::<lambda(const QHttpServerRequest&)>&}]’
      main.cpp:72:36:   required from here
      include/QtHttpServer/qhttpserverrouterviewtraits.h:152:11: error: no type named ‘ReturnType’ in ‘using FunctionTraits = using FTraits = struct QtPrivate::FunctionTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&>’ {aka ‘struct QtPrivate::FunctionTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&>’}
        152 |     using ReturnType = typename Helpers::FunctionTraits::ReturnType;
            |           ^~~~~~~~~~
      In file included from include/QtHttpServer/QtHttpServer:6,
                       from main.cpp:52:
      include/QtHttpServer/qhttpserver.h:142:10: error: ‘bool QHttpServer::routeHelper(QtPrivate::IndexesList<Px ...>, Args&& ...) [with Rule = QHttpServerRouterRule; ViewHandler = main(int, char**)::<lambda(const QHttpServerRequest&)>&; ViewTraits = QHttpServerRouterViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>; int ...I = {0}; Args = {const char (&)[7], main(int, char**)::<lambda(const QHttpServerRequest&)>&}]’, declared using local type ‘main(int, char**)::<lambda(const QHttpServerRequest&)>’, is used but never defined [-fpermissive]
        142 |     bool routeHelper(QtPrivate::IndexesList<I...>, Args &&... args)
            |          ^~~~~~~~~~~
      include/QtHttpServer/qhttpserver.h:142:10: warning: ‘bool QHttpServer::routeHelper(QtPrivate::IndexesList<Px ...>, Args&& ...) [with Rule = QHttpServerRouterRule; ViewHandler = main(int, char**)::<lambda(const QHttpServerRequest&)>&; ViewTraits = QHttpServerRouterViewTraits<main(int, char**)::<lambda(const QHttpServerRequest&)>&, false>; int ...I = {0}; Args = {const char (&)[7], main(int, char**)::<lambda(const QHttpServerRequest&)>&}]’ used but never defined
      make: *** [Makefile:891: main.o] Error 1
      
      

      I hit on this trying to implement bindings for Qt for Python. This can be quite puzzling for the user.

      Attachments

        Issue Links

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

          Activity

            People

              cnn Qt Core & Network
              kleint Friedemann Kleint
              Vladimir Minenko Vladimir Minenko
              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