From df0e6759e8ebc1053f951d3a5398a41156e91913 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 25 Mar 2010 20:05:35 +0100 Subject: QMetaObject::normalizeType: fix uses of const and template. 'const' was not removed from templated class This even fixes compilation errors if using const return templated types We can change the normalized signature in Qt 4.7 as it has already changed and we have code to check that if moc revision < 5 it will renormalize all the symbols cf commit b881d8fb99972f1bd04ab4c84843cc8d43ddbeed Task-number: QTBUG-7421 Reviewed-by: Brad Reviewed-by: Kent Hansen --- src/corelib/kernel/qmetaobject_p.h | 4 +++- tests/auto/moc/tst_moc.cpp | 11 +++++++++++ tests/auto/qmetaobject/tst_qmetaobject.cpp | 6 ++++++ tests/auto/qobject/tst_qobject.cpp | 20 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index a176149..1f4bd2f 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -196,7 +196,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc if (*(e-1) == '&') { // treat const reference as value t += 6; --e; - } else if (is_ident_char(*(e-1))) { // treat const value as value + } else if (is_ident_char(*(e-1)) || *(e-1) == '>') { // treat const value as value t += 6; } } @@ -294,6 +294,8 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc if (adjustConst && t != e && *t == '&') { // treat const ref as value ++t; + } else if (adjustConst && !star) { + // treat const as value } else if (!star) { // move const to the front (but not if const comes after a *) result.prepend("const "); diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index 30c2721..8890a15 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -1302,6 +1302,17 @@ void tst_Moc::QTBUG5590_dummyProperty() QCOMPARE(o.value2(), 82); } +class QTBUG7421_ReturnConstTemplate: public QObject +{ Q_OBJECT +public slots: + const QList returnConstTemplate1() { return QList(); } + QList const returnConstTemplate2() { return QList(); } + const int returnConstInt() { return 0; } + const QString returnConstString(const QString s) { return s; } + QString const returnConstString2( QString const s) { return s; } +}; + + QTEST_APPLESS_MAIN(tst_Moc) #include "tst_moc.moc" diff --git a/tests/auto/qmetaobject/tst_qmetaobject.cpp b/tests/auto/qmetaobject/tst_qmetaobject.cpp index bb4a0d2..e81607e 100644 --- a/tests/auto/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/qmetaobject/tst_qmetaobject.cpp @@ -706,6 +706,12 @@ void tst_QMetaObject::normalizedSignature_data() QTest::newRow("const6") << "void foo(QList)" << "void foo(QList)"; QTest::newRow("const7") << "void foo(QList)" << "void foo(QList)"; QTest::newRow("const8") << "void foo(QList)" << "void foo(QList)"; + QTest::newRow("const9") << "void foo(const Foo)" << "void foo(Foo)"; + QTest::newRow("const10") << "void foo(Fooconst)" << "void foo(Foo)"; + QTest::newRow("const11") << "void foo(Foo *const)" << "void foo(Foo*const)"; + QTest::newRow("const12") << "void foo(Fooconst*const *const)" << "void foo(Foo*const*const)"; + QTest::newRow("const13") << "void foo(const Foo&)" << "void foo(Foo)"; + QTest::newRow("const14") << "void foo(Fooconst&)" << "void foo(Foo)"; } void tst_QMetaObject::normalizedSignature() diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index 8da3484..08b7c19 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -2088,6 +2088,9 @@ signals: void typePointerConstRefSignal(Class * const &); + void constTemplateSignal1( Template ); + void constTemplateSignal2( Template< const int >); + public slots: void uintPointerSlot(uint *) { } void ulongPointerSlot(ulong *) { } @@ -2124,6 +2127,10 @@ public slots: void typeConstRefSlot(Template const &) {} void typePointerConstRefSlot(Class * const &) {} + + void constTemplateSlot1(Template const) {} + void constTemplateSlot2(const Template ) {} + void constTemplateSlot3(const Template< const int >) {} }; #include "oldnormalizeobject.h" @@ -2526,6 +2533,19 @@ void tst_QObject::normalize() QVERIFY(object.connect(&object, SIGNAL(typePointerConstRefSignal(Class*)), SLOT(typePointerConstRefSlot(Class*)))); + + QVERIFY( connect(&object, SIGNAL(constTemplateSignal1(Template )), + &object , SLOT(constTemplateSlot1 (Template ) ) )); + QVERIFY( connect(&object, SIGNAL(constTemplateSignal1(Template )), + &object , SLOT(constTemplateSlot2 (Template ) ) )); + QVERIFY( connect(&object, SIGNAL(constTemplateSignal2(Template )), + &object , SLOT(constTemplateSlot3(Template ) ) )); + + //type does not match + QTest::ignoreMessage(QtWarningMsg, "QObject::connect: Incompatible sender/receiver arguments\n" + " NormalizeObject::constTemplateSignal1(Template) --> NormalizeObject::constTemplateSlot3(Template)"); + QVERIFY(!connect(&object, SIGNAL(constTemplateSignal1(Template )), + &object , SLOT(constTemplateSlot3(Template ) ) )); } class SiblingDeleter : public QObject -- cgit v0.12