moc: fix compilation of signals returning pointers.

That was a regression introduced in 1c5db1aff

Example:
  signals: int *someSignal();
would produce this code:
   int* _t0 = int*();
which does not compile

So have special handling for pointer to change it to '= 0'

Change-Id: Ie695e15e309d15c3cfd5c5a69ac8bf6d61ae9915
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
bb10
Olivier Goffart 2012-04-11 14:10:12 +02:00 committed by Qt by Nokia
parent 53112c5167
commit d1329e43cb
2 changed files with 22 additions and 2 deletions

View File

@ -1036,8 +1036,14 @@ void Generator::generateSignal(FunctionDef *def,int index)
fprintf(out, "%s _t%d%s", a.type.name.constData(), offset++, a.rightType.constData());
}
fprintf(out, ")%s\n{\n", constQualifier);
if (def->type.name.size() && def->normalizedType.size())
fprintf(out, " %s _t0 = %s();\n", noRef(def->normalizedType).constData(), noRef(def->normalizedType).constData());
if (def->type.name.size() && def->normalizedType.size()) {
QByteArray returnType = noRef(def->normalizedType);
if (returnType.endsWith('*')) {
fprintf(out, " %s _t0 = 0;\n", returnType.constData());
} else {
fprintf(out, " %s _t0 = %s();\n", returnType.constData(), returnType.constData());
}
}
fprintf(out, " void *_a[] = { ");
if (def->normalizedType.isEmpty()) {

View File

@ -4904,6 +4904,8 @@ signals:
int returnInt(int);
void returnVoid(int);
CustomType returnCustomType(int);
QObject *returnPointer();
public slots:
QVariant returnVariantSlot(int i) { return i; }
QString returnStringSlot(int i) { return QString::number(i); }
@ -4912,6 +4914,8 @@ public slots:
void returnVoidSlot() {}
int return23() { return 23; }
QString returnHello() { return QStringLiteral("hello"); }
QObject *returnThisSlot1() { return this; }
ReturnValue *returnThisSlot2() { return this; }
public:
struct VariantFunctor {
QVariant operator()(int i) { return i; }
@ -4964,6 +4968,7 @@ void tst_QObject::returnValue()
QCOMPARE(emit r.returnInt(45), int());
emit r.returnVoid(45);
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
}
{ // connected to a slot returning the same type
CheckInstanceCount checker;
@ -4976,6 +4981,8 @@ void tst_QObject::returnValue()
QCOMPARE(emit r.returnInt(45), int(45));
QVERIFY(connect(&r, &ReturnValue::returnCustomType, &receiver, &ReturnValue::returnCustomTypeSlot, type));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType(45).value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnThisSlot1, type));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(&receiver));
}
if (!isBlockingQueued) { // connected to simple functions or functor
CheckInstanceCount checker;
@ -5004,6 +5011,8 @@ void tst_QObject::returnValue()
QCOMPARE((emit r.returnCustomType(48)).value(), CustomType(48).value());
QVERIFY(connect(&r, &ReturnValue::returnVoid, &receiver, &ReturnValue::returnCustomTypeSlot, type));
emit r.returnVoid(48);
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnThisSlot2, type));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(&receiver));
}
if (!isBlockingQueued) { // connected to functor with different type
CheckInstanceCount checker;
@ -5028,6 +5037,8 @@ void tst_QObject::returnValue()
QCOMPARE(emit r.returnInt(45), int());
QVERIFY(connect(&r, &ReturnValue::returnCustomType, &receiver, &ReturnValue::returnVoidSlot, type));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnVoidSlot, type));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
}
if (!isBlockingQueued) {
// queued connection should not forward the return value
@ -5041,6 +5052,9 @@ void tst_QObject::returnValue()
QCOMPARE(emit r.returnInt(45), int());
QVERIFY(connect(&r, &ReturnValue::returnCustomType, &receiver, &ReturnValue::returnCustomTypeSlot, Qt::QueuedConnection));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnThisSlot1, Qt::QueuedConnection));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
QCoreApplication::processEvents();
QVERIFY(connect(&r, &ReturnValue::returnVariant, &receiver, &ReturnValue::returnStringSlot, Qt::QueuedConnection));