clangqt6qgadget

Is it possible to fix failed build of multiple inheritance from Q_GADGET with Clang and Qt 6?


In one my project, a build on MacOS under GitHub action:

macos:
  name: macos
  runs-on: macos-11

Subproject JKQtPlotter fails with:

[ 64%] Building CXX object 3rdparty/JKQtPlotter/lib/jkqtplotter/CMakeFiles/JKQTPlotterSharedLib.dir/JKQTPlotterSharedLib_autogen/mocs_compilation.cpp.o
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/mocs_compilation.cpp:2:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/moc_jkqtpbarchart.cpp:10:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/../../graphs/jkqtpbarchart.h:25:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/QPainter:1:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/qpainter.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/qpixmap.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qsharedpointer.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qsharedpointer_impl.h:65:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qobject.h:54:
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:872:49: error: member 'qt_check_for_QGADGET_macro' found in multiple base classes of different types
            IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *),
                                                ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:1189:25: note: in instantiation of template class 'QtPrivate::IsGadgetHelper<JKQTPBarVerticalGraph>' requested here
                     | (IsGadgetHelper<T>::IsGadgetOrDerivedFrom ? QMetaType::IsGadget : 0)
                        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2367:21: note: in instantiation of template class 'QtPrivate::QMetaTypeTypeFlags<JKQTPBarVerticalGraph>' requested here
        /*.flags=*/ QMetaTypeTypeFlags<T>::Flags,
                    ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2494:48: note: in instantiation of static data member 'QtPrivate::QMetaTypeInterfaceWrapper<JKQTPBarVerticalGraph>::metaType' requested here
        return &QMetaTypeInterfaceWrapper<Ty>::metaType;
                                               ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2538:16: note: in instantiation of function template specialization 'QtPrivate::qTryMetaTypeInterfaceForType<qt_meta_stringdata_JKQTPBarVerticalGraph_t, QtPrivate::TypeAndForceComplete<JKQTPBarVerticalGraph, std::integral_constant<bool, true>>>' requested here
    QtPrivate::qTryMetaTypeInterfaceForType<Unique, T>()...
               ^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/moc_jkqtpbarchart.cpp:95:1: note: in instantiation of variable template specialization 'qt_incomplete_metaTypeArray<qt_meta_stringdata_JKQTPBarVerticalGraph_t, QtPrivate::TypeAndForceComplete<JKQTPBarVerticalGraph, std::integral_constant<bool, true>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<int, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<unsigned long, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<int, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<unsigned long, std::integral_constant<bool, false>>>' requested here
qt_incomplete_metaTypeArray<qt_meta_stringdata_JKQTPBarVerticalGraph_t
^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/./jkqtplotter/jkqtpgraphsbasestylingmixins.h:49:9: note: member found by ambiguous name lookup
        Q_GADGET
        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:193:18: note: expanded from macro 'Q_GADGET'
#define Q_GADGET Q_GADGET_EXPORT()
                 ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:182:10: note: expanded from macro 'Q_GADGET_EXPORT'
    void qt_check_for_QGADGET_macro(); \
         ^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/./jkqtplotter/jkqtpgraphsbasestylingmixins.h:396:9: note: member found by ambiguous name lookup
        Q_GADGET
        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:193:18: note: expanded from macro 'Q_GADGET'
#define Q_GADGET Q_GADGET_EXPORT()
                 ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:182:10: note: expanded from macro 'Q_GADGET_EXPORT'
    void qt_check_for_QGADGET_macro(); \
         ^
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/mocs_compilation.cpp:2:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/moc_jkqtpbarchart.cpp:10:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/../../graphs/jkqtpbarchart.h:25:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/QPainter:1:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/qpainter.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtGui.framework/Headers/qpixmap.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qsharedpointer.h:48:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qsharedpointer_impl.h:65:
In file included from /Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qobject.h:54:
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:872:49: error: member 'qt_check_for_QGADGET_macro' found in multiple base classes of different types
            IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *),
                                                ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:1189:25: note: in instantiation of template class 'QtPrivate::IsGadgetHelper<JKQTPBarVerticalErrorGraph>' requested here
                     | (IsGadgetHelper<T>::IsGadgetOrDerivedFrom ? QMetaType::IsGadget : 0)
                        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2367:21: note: in instantiation of template class 'QtPrivate::QMetaTypeTypeFlags<JKQTPBarVerticalErrorGraph>' requested here
        /*.flags=*/ QMetaTypeTypeFlags<T>::Flags,
                    ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2494:48: note: in instantiation of static data member 'QtPrivate::QMetaTypeInterfaceWrapper<JKQTPBarVerticalErrorGraph>::metaType' requested here
        return &QMetaTypeInterfaceWrapper<Ty>::metaType;
                                               ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qmetatype.h:2538:16: note: in instantiation of function template specialization 'QtPrivate::qTryMetaTypeInterfaceForType<qt_meta_stringdata_JKQTPBarVerticalErrorGraph_t, QtPrivate::TypeAndForceComplete<JKQTPBarVerticalErrorGraph, std::integral_constant<bool, true>>>' requested here
    QtPrivate::qTryMetaTypeInterfaceForType<Unique, T>()...
               ^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/moc_jkqtpbarchart.cpp:204:1: note: in instantiation of variable template specialization 'qt_incomplete_metaTypeArray<qt_meta_stringdata_JKQTPBarVerticalErrorGraph_t, QtPrivate::TypeAndForceComplete<JKQTPBarVerticalErrorGraph, std::integral_constant<bool, true>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<int, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<unsigned long, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<int, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false>>, QtPrivate::TypeAndForceComplete<unsigned long, std::integral_constant<bool, false>>>' requested here
qt_incomplete_metaTypeArray<qt_meta_stringdata_JKQTPBarVerticalErrorGraph_t
^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/./jkqtplotter/jkqtpgraphsbasestylingmixins.h:49:9: note: member found by ambiguous name lookup
        Q_GADGET
        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:193:18: note: expanded from macro 'Q_GADGET'
#define Q_GADGET Q_GADGET_EXPORT()
                 ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:182:10: note: expanded from macro 'Q_GADGET_EXPORT'
    void qt_check_for_QGADGET_macro(); \
         ^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/./jkqtplotter/jkqtpgraphsbasestylingmixins.h:396:9: note: member found by ambiguous name lookup
        Q_GADGET
        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:193:18: note: expanded from macro 'Q_GADGET'
#define Q_GADGET Q_GADGET_EXPORT()
                 ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:182:10: note: expanded from macro 'Q_GADGET_EXPORT'
    void qt_check_for_QGADGET_macro(); \
         ^
/Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/./jkqtplotter/jkqtpgraphsbaseerrors.h:315:9: note: member found by ambiguous name lookup
        Q_GADGET
        ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:193:18: note: expanded from macro 'Q_GADGET'
#define Q_GADGET Q_GADGET_EXPORT()
                 ^
/Users/runner/work/md-pdf/Qt/6.3.1/macos/lib/QtCore.framework/Headers/qtmetamacros.h:182:10: note: expanded from macro 'Q_GADGET_EXPORT'
    void qt_check_for_QGADGET_macro(); \
         ^
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/mocs_compilation.cpp:2:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/moc_jkqtpbarchart.cpp:10:
In file included from /Users/runner/work/md-pdf/md-pdf/3rdparty/JKQtPlotter/lib/jkqtplotter/JKQTPlotterSharedLib_autogen/XT4CMLABNO/../../graphs/jkqtpbarchart.h:25:

I don't have MacOS to play with this problem. Maybe somebody knows how to fix it? Thanks.

To reproduce this error, just MOC and build the following header with Clang:

#pragma once

#include <QObject>


class Gadget1 {
    Q_GADGET
};

class Gadget2 {
    Q_GADGET
};

class Object1
    :   public QObject
{
    Q_OBJECT
};

class Check
    :   public Object1
    ,   public Gadget1
    ,   public Gadget2
{
    Q_OBJECT
};

Solution

  • Ok, this is an issue of Qt6 when building with Clang. Qt Bug has been confirmed. So I decided to post such answer.