From 4da1a3b63445c04d4ca4acae448e9b6b046938c3 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 19 Jul 2010 17:04:06 +0200 Subject: moc: Slot with complex template default value does not compile The way we detect the end of a default argument does not take in account template parametter. It is unfortunatelly not trivial to do it properly without semantic information So we will use heuristics and if the number of < matches the number of > we consider it is a template. Or if we have a '=' we consider it is not a template. Task-number: QTBUG-12260 Reviewed-by: Roberto Raggi --- src/tools/moc/moc.cpp | 22 +++++++++++++++++++++- tests/auto/moc/tst_moc.cpp | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 10a80f3..84d1567 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1208,6 +1208,12 @@ bool Moc::until(Token target) { default: break; } } + + //when searching commas within the default argument, we should take care of template depth (anglecount) + // unfortunatelly, we do not have enough semantic information to know if '<' is the operator< or + // the begining of a template type. so we just use heuristics. + int possible = -1; + while (index < symbols.size()) { Token t = symbols.at(index++).token; switch (t) { @@ -1226,8 +1232,16 @@ bool Moc::until(Token target) { && braceCount <= 0 && brackCount <= 0 && parenCount <= 0 - && (target != RANGLE || angleCount <= 0)) + && (target != RANGLE || angleCount <= 0)) { + if (target != COMMA || angleCount <= 0) + return true; + possible = index; + } + + if (target == COMMA && t == EQ && possible != -1) { + index = possible; return true; + } if (braceCount < 0 || brackCount < 0 || parenCount < 0 || (target == RANGLE && angleCount < 0)) { @@ -1235,6 +1249,12 @@ bool Moc::until(Token target) { break; } } + + if(target == COMMA && angleCount != 0 && possible != -1) { + index = possible; + return true; + } + return false; } diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index 19f3677..4fcc7bd 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -491,6 +491,7 @@ private slots: void typenameWithUnsigned(); void warnOnVirtualSignal(); void QTBUG5590_dummyProperty(); + void QTBUG12260_defaultTemplate(); signals: void sigWithUnsignedArg(unsigned foo); void sigWithSignedArg(signed foo); @@ -1340,6 +1341,20 @@ signals: void testSignal(TestTemplate2); }; +class QTBUG12260_defaultTemplate_Object : public QObject +{ Q_OBJECT +public slots: + void doSomething(QHash values = QHash()) { Q_UNUSED(values); } + void doAnotherThing(bool a = (1 < 3), bool b = (1 > 4)) { Q_UNUSED(a); Q_UNUSED(b); } +}; + + +void tst_Moc::QTBUG12260_defaultTemplate() +{ + QVERIFY(QTBUG12260_defaultTemplate_Object::staticMetaObject.indexOfSlot("doSomething(QHash)") != -1); + QVERIFY(QTBUG12260_defaultTemplate_Object::staticMetaObject.indexOfSlot("doAnotherThing(bool,bool)") != -1); +} + QTEST_APPLESS_MAIN(tst_Moc) #include "tst_moc.moc" -- cgit v0.12