From 01648005f1f546dc0281155fecd94b4f47a94584 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 30 Jun 2010 15:52:20 +0200 Subject: Moc: fix compilation when templated types with multiple arguments are used. Each template argument need to be normalized separately. Else, the const type of one argument may end up moved in the first argument. (And then the compilation of the generated moc file would fail as the types would not match) Reviewed-by: Kent Hansen Task-number: QTBUG-11647 --- src/corelib/kernel/qmetaobject_p.h | 11 +++++++---- tests/auto/moc/tst_moc.cpp | 19 +++++++++++++++++++ tests/auto/qmetaobject/tst_qmetaobject.cpp | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index b538787..4a03874 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -276,12 +276,15 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc ++templdepth; if (c == '>') --templdepth; - if (templdepth == 0) { + if (templdepth == 0 || (templdepth == 1 && c == ',')) { result += normalizeTypeInternal(tt, t-1, fixScope, false); result += c; - if (*t == '>') - result += ' '; // avoid >> - break; + if (templdepth == 0) { + if (*t == '>') + result += ' '; // avoid >> + break; + } + tt = t; } } } diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index a56d842..19f3677 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -1322,6 +1322,25 @@ public slots: void foo(struct const_ *) {}; }; + +template +class TestTemplate2 +{ +}; + +class QTBUG11647_constInTemplateParameter : public QObject +{ Q_OBJECT +public slots: + void testSlot(TestTemplate2) {} + void testSlot2(TestTemplate2) {} + void testSlot3(TestTemplate2 const *, + TestTemplate2< TestTemplate2 < void, int > , unsigned char *> > ) {} + +signals: + void testSignal(TestTemplate2); +}; + + 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 b6d4558..62416b1 100644 --- a/tests/auto/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/qmetaobject/tst_qmetaobject.cpp @@ -740,6 +740,8 @@ void tst_QMetaObject::normalizedType_data() QTest::newRow("template5") << "QList< ::Foo::Bar>" << "QList< ::Foo::Bar>"; QTest::newRow("template6") << "QList<::Foo::Bar>" << "QList<::Foo::Bar>"; QTest::newRow("template7") << "QList >" << "QList >"; + QTest::newRow("template8") << "QMap" << "QMap"; + QTest::newRow("template9") << "QPair , QPair > >" << "QPair,QPair > >"; QTest::newRow("value1") << "const QString &" << "QString"; QTest::newRow("value2") << "QString const &" << "QString"; QTest::newRow("constInName1") << "constconst" << "constconst"; -- cgit v0.12