typeNameForCast: use add_pointer instead of string manipulation
Relying on string manipulation leads to -Wredundant-parens warnings in the best case, and to non-compiling code (when using typedefs) in the worst case. We can avoid both issues by simply generating code that uses add_pointer, which takes care of reference types (even typedef'd ones), and creates no warnings about parens (as we don't write any anymore). Fixes: QTBUG-100915 Pick-to: 6.3 6.2 Change-Id: Ic5b1cbfda20d920d11f51beeb62e9479261d5f00 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>bb10
parent
9078b41dde
commit
8079361852
|
|
@ -320,7 +320,7 @@ void Moc::parseFunctionArguments(FunctionDef *def)
|
|||
arg.rightType += lexem();
|
||||
}
|
||||
arg.normalizedType = normalizeType(QByteArray(arg.type.name + ' ' + arg.rightType));
|
||||
arg.typeNameForCast = normalizeType(QByteArray(noRef(arg.type.name) + "(*)" + arg.rightType));
|
||||
arg.typeNameForCast = QByteArray("std::add_pointer_t<"+arg.normalizedType+">");
|
||||
if (test(EQ))
|
||||
arg.isDefault = true;
|
||||
def->arguments += arg;
|
||||
|
|
|
|||
|
|
@ -362,6 +362,8 @@ QT_WARNING_PUSH
|
|||
QT_WARNING_DISABLE_CLANG("-Wignored-qualifiers")
|
||||
QT_WARNING_DISABLE_GCC("-Wignored-qualifiers")
|
||||
|
||||
using ObjectCRef = const QObject &;
|
||||
|
||||
class TestClass : public MyNamespace::TestSuperClass, public DONT_CONFUSE_MOC(MyStruct),
|
||||
public DONT_CONFUSE_MOC_EVEN_MORE(MyStruct2, dummy, ignored)
|
||||
{
|
||||
|
|
@ -557,6 +559,7 @@ signals:
|
|||
//
|
||||
public slots:
|
||||
void const slotWithSillyConst() {}
|
||||
void slotTakingCRefViaTypedef(ObjectCRef o) { this->setObjectName(o.objectName()); }
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void const slotWithSillyConst2() {}
|
||||
|
|
@ -686,6 +689,7 @@ private slots:
|
|||
void preprocessorConditionals();
|
||||
void blackslashNewlines();
|
||||
void slotWithSillyConst();
|
||||
void slotTakingCRefViaTypedef();
|
||||
void testExtraData();
|
||||
void testExtraDataForEnum();
|
||||
void namespaceTypeProperty();
|
||||
|
|
@ -1074,6 +1078,15 @@ void tst_Moc::slotWithSillyConst()
|
|||
QVERIFY(mobj->indexOfSlot("slotWithVoidStar(void*)") != -1);
|
||||
}
|
||||
|
||||
void tst_Moc::slotTakingCRefViaTypedef()
|
||||
{
|
||||
TestClass tst;
|
||||
QObject obj;
|
||||
obj.setObjectName("works");
|
||||
QMetaObject::invokeMethod(&tst, "slotTakingCRefViaTypedef", Q_ARG(ObjectCRef, obj));
|
||||
QCOMPARE(obj.objectName(), "works");
|
||||
}
|
||||
|
||||
void tst_Moc::testExtraData()
|
||||
{
|
||||
const QMetaObject *mobj = &PropertyTestClass::staticMetaObject;
|
||||
|
|
|
|||
Loading…
Reference in New Issue