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

moc mis-parses third-party headers and generates invalid code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • 6.5
    • 6.4.2
    • Build tools: moc
    • None
    • Linux/X11
    • 93201df99 (10.0)

    Description

      Trying to build a Qt project fails if any mocable file includes LLVM's (>= 15) Format.h. It appears that moc gets deeply confused parsing this unrelated header file and erroneously uses its data types in the generated code.
      Presumably similar dangers are lurking in other code bases.

      /usr/bin/qmake6 -o Makefile ../moctest/moctest.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
      g++ -c -pipe -g -Wall -Wextra -fPIC -D_REENTRANT -DQT_QML_DEBUG -DQT_CORE_LIB -I../moctest -I. -I/usr/include/qt6 -I/usr/include/qt6/QtCore -I. -I/usr/lib/qt6/mkspecs/linux-g++ -o main.o ../moctest/main.cpp
      In file included from ../moctest/main.cpp:14:
      ./main.moc:58:43: error: ‘llvm::yaml::O’ has not been declared
         58 | Q_CONSTINIT const QMetaObject llvm::yaml::O::staticMetaObject = { {
            |                                           ^
      ./main.moc:62:5: error: ‘qt_static_metacall’ was not declared in this scope
         62 |     qt_static_metacall,
            |     ^~~~~~~~~~~~~~~~~~
      ./main.moc:71:18: error: ‘llvm::yaml::O’ has not been declared
         71 | void llvm::yaml::O::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
            |                  ^
      ./main.moc:79:32: error: ‘llvm::yaml::O’ has not been declared
         79 | const QMetaObject *llvm::yaml::O::metaObject() const
            |                                ^
      ./main.moc:79:48: error: non-member function ‘const QMetaObject* metaObject()’ cannot have cv-qualifier
         79 | const QMetaObject *llvm::yaml::O::metaObject() const
            |                                                ^~~~~
      ./main.moc: In function ‘const QMetaObject* metaObject()’:
      ./main.moc:81:21: error: ‘QScopedPointer<QObjectData> QObject::d_ptr’ is protected within this context
         81 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
            |                     ^~~~~
      In file included from /usr/include/qt6/QtCore/QObject:1,
                       from ../moctest/main.cpp:1:
      /usr/include/qt6/QtCore/qobject.h:403:33: note: declared protected here
        403 |     QScopedPointer<QObjectData> d_ptr;
            |                                 ^~~~~
      ./main.moc:81:21: error: invalid use of non-static data member ‘QObject::d_ptr’
         81 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
            |                     ^~~~~
      /usr/include/qt6/QtCore/qobject.h:403:33: note: declared here
        403 |     QScopedPointer<QObjectData> d_ptr;
            |                                 ^~~~~
      ./main.moc:81:50: error: ‘QScopedPointer<QObjectData> QObject::d_ptr’ is protected within this context
         81 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
            |                                                  ^~~~~
      /usr/include/qt6/QtCore/qobject.h:403:33: note: declared protected here
        403 |     QScopedPointer<QObjectData> d_ptr;
            |                                 ^~~~~
      ./main.moc:81:50: error: invalid use of non-static data member ‘QObject::d_ptr’
         81 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
            |                                                  ^~~~~
      /usr/include/qt6/QtCore/qobject.h:403:33: note: declared here
        403 |     QScopedPointer<QObjectData> d_ptr;
            |                                 ^~~~~
      ./main.moc: At global scope:
      ./main.moc:84:19: error: ‘llvm::yaml::O’ has not been declared
         84 | void *llvm::yaml::O::qt_metacast(const char *_clname)
            |                   ^
      ./main.moc: In function ‘void* qt_metacast(const char*)’:
      ./main.moc:88:35: error: invalid use of ‘this’ in non-member function
         88 |         return static_cast<void*>(this);
            |                                   ^~~~
      ./main.moc:89:32: error: cannot call member function ‘virtual void* QObject::qt_metacast(const char*)’ without object
         89 |     return QObject::qt_metacast(_clname);
            |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
      ./main.moc: At global scope:
      ./main.moc:92:17: error: ‘llvm::yaml::O’ has not been declared
         92 | int llvm::yaml::O::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
            |                 ^
      ./main.moc: In function ‘int qt_metacall(QMetaObject::Call, int, void**)’:
      ./main.moc:94:31: error: cannot call member function ‘virtual int QObject::qt_metacall(QMetaObject::Call, int, void**)’ without object
         94 |     _id = QObject::qt_metacall(_c, _id, _a);
            |           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
      make: *** [Makefile:573: main.o] Error 1
      

      Attachments

        Activity

          People

            kandeler Christian Kandeler
            kandeler Christian Kandeler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: