diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2010-03-25 19:05:35 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2010-03-26 11:25:13 (GMT) |
commit | df0e6759e8ebc1053f951d3a5398a41156e91913 (patch) | |
tree | 18396f0e4763f37ada5acc3b6f60fd151d26fbaf | |
parent | e7eb7bdf63791ed03257f2f23b1f515e4d89e054 (diff) | |
download | Qt-df0e6759e8ebc1053f951d3a5398a41156e91913.zip Qt-df0e6759e8ebc1053f951d3a5398a41156e91913.tar.gz Qt-df0e6759e8ebc1053f951d3a5398a41156e91913.tar.bz2 |
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
-rw-r--r-- | src/corelib/kernel/qmetaobject_p.h | 4 | ||||
-rw-r--r-- | tests/auto/moc/tst_moc.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qmetaobject/tst_qmetaobject.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qobject/tst_qobject.cpp | 20 |
4 files changed, 40 insertions, 1 deletions
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<int> returnConstTemplate1() { return QList<int>(); } + QList<int> const returnConstTemplate2() { return QList<int>(); } + 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<const int>)" << "void foo(QList<const int>)"; QTest::newRow("const7") << "void foo(QList<const int*>)" << "void foo(QList<const int*>)"; QTest::newRow("const8") << "void foo(QList<int const*>)" << "void foo(QList<const int*>)"; + QTest::newRow("const9") << "void foo(const Foo<Bar>)" << "void foo(Foo<Bar>)"; + QTest::newRow("const10") << "void foo(Foo<Bar>const)" << "void foo(Foo<Bar>)"; + QTest::newRow("const11") << "void foo(Foo<Bar> *const)" << "void foo(Foo<Bar>*const)"; + QTest::newRow("const12") << "void foo(Foo<Bar>const*const *const)" << "void foo(Foo<Bar>*const*const)"; + QTest::newRow("const13") << "void foo(const Foo<Bar>&)" << "void foo(Foo<Bar>)"; + QTest::newRow("const14") << "void foo(Foo<Bar>const&)" << "void foo(Foo<Bar>)"; } 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<int > ); + void constTemplateSignal2( Template< const int >); + public slots: void uintPointerSlot(uint *) { } void ulongPointerSlot(ulong *) { } @@ -2124,6 +2127,10 @@ public slots: void typeConstRefSlot(Template<Class const &> const &) {} void typePointerConstRefSlot(Class * const &) {} + + void constTemplateSlot1(Template<int > const) {} + void constTemplateSlot2(const Template<int > ) {} + 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 <int>)), + &object , SLOT(constTemplateSlot1 (Template<int > ) ) )); + QVERIFY( connect(&object, SIGNAL(constTemplateSignal1(Template <int>)), + &object , SLOT(constTemplateSlot2 (Template<int > ) ) )); + QVERIFY( connect(&object, SIGNAL(constTemplateSignal2(Template <const int>)), + &object , SLOT(constTemplateSlot3(Template<int const > ) ) )); + + //type does not match + QTest::ignoreMessage(QtWarningMsg, "QObject::connect: Incompatible sender/receiver arguments\n" + " NormalizeObject::constTemplateSignal1(Template<int>) --> NormalizeObject::constTemplateSlot3(Template<const int>)"); + QVERIFY(!connect(&object, SIGNAL(constTemplateSignal1(Template <int>)), + &object , SLOT(constTemplateSlot3(Template<int const> ) ) )); } class SiblingDeleter : public QObject |