summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/moc/moc.cpp5
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp16
2 files changed, 20 insertions, 1 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index 6086eb0ddb..e408b7c8ac 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -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);
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 6a84eb244a..f3abe9b5ff 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -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"