moc: fix Q_INVOKABLE returning references
The moc generated code would not compile otherwise Keep Moc::parseFunction and Moc::parseMaybeFunction in sync (the first is used for signals and slots, and the second for normal functions such as Q_INVOKABLE) Last patch that introduced function pointer updated parseFunction but not parseMaybeFunction When a slot return a reference, moc generate code that make the MetaObject system think it is a void, so qt_metacall and invokeMethod do not mess with the return value. But when we want to take the function signature, in the IndexOfMethod call, we need to have the exact return type. Change-Id: I4661218d7ce367ad3934e73929e7d04f0a6dbc09 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
parent
a254611ba1
commit
9924a637cc
@ -503,8 +503,11 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def)
|
||||
}
|
||||
|
||||
// we don't support references as return types, it's too dangerous
|
||||
if (def->type.referenceType == Type::Reference)
|
||||
if (def->type.referenceType == Type::Reference) {
|
||||
QByteArray rawName = def->type.rawName;
|
||||
def->type = Type("void");
|
||||
def->type.rawName = rawName;
|
||||
}
|
||||
|
||||
def->normalizedType = normalizeType(def->type.name);
|
||||
|
||||
|
@ -373,6 +373,11 @@ public slots:
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void const slotWithSillyConst2() {}
|
||||
Q_INVOKABLE QObject& myInvokableReturningRef()
|
||||
{ return *this; }
|
||||
Q_INVOKABLE const QObject& myInvokableReturningConstRef() const
|
||||
{ return *this; }
|
||||
|
||||
|
||||
// that one however should be fine
|
||||
public slots:
|
||||
@ -530,6 +535,7 @@ private slots:
|
||||
void privateClass();
|
||||
void cxx11Enums_data();
|
||||
void cxx11Enums();
|
||||
void returnRefs();
|
||||
|
||||
signals:
|
||||
void sigWithUnsignedArg(unsigned foo);
|
||||
@ -1687,6 +1693,16 @@ void tst_Moc::cxx11Enums()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Moc::returnRefs()
|
||||
{
|
||||
TestClass tst;
|
||||
const QMetaObject *mobj = tst.metaObject();
|
||||
QVERIFY(mobj->indexOfMethod("myInvokableReturningRef()") != -1);
|
||||
QVERIFY(mobj->indexOfMethod("myInvokableReturningConstRef()") != -1);
|
||||
// Those two functions are copied from the qscriptextqobject test in qtscript
|
||||
// they used to cause miscompilation of the moc generated file.
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_Moc)
|
||||
#include "tst_moc.moc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user