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

moc generates invalid cpp file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12
    • Build tools: moc
    • None
    • Linux/Wayland

    Description

      moc generates invalid C++ code (invalid syntax)  upon a complex situation involving macros, while trying to automate the creation of connections of signals to c++11 lambdas:

      void LambdaConnector::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)\{ if (_c == QMetaObject::InvokeMetaMethod) { auto *_t = static_cast<LambdaConnector *>(_o); Q_UNUSED(_t) switch (_id) { case 0: _t->call((*reinterpret_cast< int int(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break; case 1: _t->call((*reinterpret_cast< QString(*)>(_a[1]))); break; case 2: _t->call(); break; default: ; } }} 
      

      It is reproducible by adding the attached file into a project and just compiling it. I have used for example: https://github.com/jasondegraw/Qt-CMake-HelloWorld.git and just added the header file into the CMake file and rebuilt the project. You will get the error like:

      Qt-CMake-HelloWorld/build/helloworld_autogen/EWIEGA46WW/moc_LambdaConnector.cpp:75:55: error: two or more data types in declaration of ‘type name’
         75 |         case 0: _t->call((*reinterpret_cast< int int(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
            |                                                       ^
      make[2]: *** [CMakeFiles/helloworld.dir/build.make:89: CMakeFiles/helloworld.dir/helloworld_autogen/mocs_compilation.cpp.o] Error 1
      make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/helloworld.dir/all] Error 2
      make: *** [Makefile:103: all] Error 2
      

      If you run the header file via the preprocessor the generated code is valid.

      Attachments

        Activity

          People

            fabiankosmale Fabian Kosmale
            ferencld Ferenc Deak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: