moc: put the QPrivateSignal argument in the arg array

Even if it is normaly not used, templated code might still try to access it

Task-number: QTBUG-59414
Change-Id: I9f7aadd714843059c8f89cdac48c60a3e2ca7294
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Olivier Goffart 2017-03-11 18:50:52 +01:00 committed by Olivier Goffart (Woboq GmbH)
parent d8a123841c
commit 8c0194f763
2 changed files with 18 additions and 6 deletions

View File

@ -1483,10 +1483,7 @@ void Generator::generateSignal(FunctionDef *def,int index)
}
Q_ASSERT(!def->normalizedType.isEmpty());
if (def->arguments.isEmpty() && def->normalizedType == "void") {
if (def->isPrivateSignal)
fprintf(out, "QPrivateSignal");
if (def->arguments.isEmpty() && def->normalizedType == "void" && !def->isPrivateSignal) {
fprintf(out, ")%s\n{\n"
" QMetaObject::activate(%s, &staticMetaObject, %d, nullptr);\n"
"}\n", constQualifier, thisPtr.constData(), index);
@ -1503,7 +1500,7 @@ void Generator::generateSignal(FunctionDef *def,int index)
if (def->isPrivateSignal) {
if (!def->arguments.isEmpty())
fprintf(out, ", ");
fprintf(out, "QPrivateSignal");
fprintf(out, "QPrivateSignal _t%d", offset++);
}
fprintf(out, ")%s\n{\n", constQualifier);
@ -1527,7 +1524,7 @@ void Generator::generateSignal(FunctionDef *def,int index)
}
int i;
for (i = 1; i < offset; ++i)
if (def->arguments.at(i - 1).type.isVolatile)
if (i <= def->arguments.count() && def->arguments.at(i - 1).type.isVolatile)
fprintf(out, ", const_cast<void*>(reinterpret_cast<const volatile void*>(&_t%d))", i);
else
fprintf(out, ", const_cast<void*>(reinterpret_cast<const void*>(&_t%d))", i);

View File

@ -2837,6 +2837,21 @@ void tst_Moc::privateSignalConnection()
// We can't use function pointer connections to private signals which are overloaded because we would have to cast in this case to:
// static_cast<void (ClassWithPrivateSignals::*)(int, ClassWithPrivateSignals::QPrivateSignal)>(&ClassWithPrivateSignals::overloadedMaybePrivate)
// Which doesn't work as ClassWithPrivateSignals::QPrivateSignal is private.
// Connecting from one private signal to another
{
ClassWithPrivateSignals classWithPrivateSignals1;
ClassWithPrivateSignals classWithPrivateSignals2;
SignalConnectionTester tester;
QObject::connect(&classWithPrivateSignals1, &ClassWithPrivateSignals::privateSignal1,
&classWithPrivateSignals2, &ClassWithPrivateSignals::privateSignal1);
QObject::connect(&classWithPrivateSignals2, &ClassWithPrivateSignals::privateSignal1,
&tester, &SignalConnectionTester::testSlot);
QVERIFY(!tester.testPassed);
classWithPrivateSignals1.emitPrivateSignals();
QVERIFY(tester.testPassed);
}
}
void tst_Moc::finalClasses_data()