summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/moc/moc.cpp20
-rw-r--r--tests/auto/moc/tst_moc.cpp22
2 files changed, 31 insertions, 11 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index da5733a..797595f 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -337,11 +337,10 @@ bool Moc::testFunctionAttribute(Token tok, FunctionDef *def)
bool Moc::parseFunction(FunctionDef *def, bool inMacro)
{
def->isVirtual = false;
- while (test(INLINE) || test(STATIC) || test(VIRTUAL)
- || testFunctionAttribute(def)) {
- if (lookup() == VIRTUAL)
- def->isVirtual = true;
- }
+ //skip modifiers and attributes
+ while (test(INLINE) || test(STATIC) ||
+ (test(VIRTUAL) && (def->isVirtual = true)) //mark as virtual
+ || testFunctionAttribute(def)) {}
bool templateFunction = (lookup() == TEMPLATE);
def->type = parseType();
if (def->type.name.isEmpty()) {
@@ -429,11 +428,10 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro)
bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def)
{
def->isVirtual = false;
- while (test(EXPLICIT) || test(INLINE) || test(STATIC) || test(VIRTUAL)
- || testFunctionAttribute(def)) {
- if (lookup() == VIRTUAL)
- def->isVirtual = true;
- }
+ //skip modifiers and attributes
+ while (test(INLINE) || test(STATIC) ||
+ (test(VIRTUAL) && (def->isVirtual = true)) //mark as virtual
+ || testFunctionAttribute(def)) {}
bool tilde = test(TILDE);
def->type = parseType();
if (def->type.name.isEmpty())
@@ -862,7 +860,7 @@ void Moc::parseSignals(ClassDef *def)
funcDef.access = FunctionDef::Protected;
parseFunction(&funcDef);
if (funcDef.isVirtual)
- error("Signals cannot be declared virtual");
+ warning("Signals cannot be declared virtual");
if (funcDef.inlineCode)
error("Not a signal declaration");
def->signalList += funcDef;
diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp
index 898cfe1..d66791f 100644
--- a/tests/auto/moc/tst_moc.cpp
+++ b/tests/auto/moc/tst_moc.cpp
@@ -488,6 +488,7 @@ private slots:
void warnOnPropertyWithoutREAD();
void constructors();
void typenameWithUnsigned();
+ void warnOnVirtualSignal();
signals:
void sigWithUnsignedArg(unsigned foo);
@@ -1180,6 +1181,27 @@ void tst_Moc::typenameWithUnsigned()
QVERIFY(mobj->indexOfSlot("l(unsignedQImage)") != -1);
}
+
+void tst_Moc::warnOnVirtualSignal()
+{
+#ifdef MOC_CROSS_COMPILED
+ QSKIP("Not tested when cross-compiled", SkipAll);
+#endif
+#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ QProcess proc;
+ proc.start("moc", QStringList(srcify("pure-virtual-signals.h")));
+ QVERIFY(proc.waitForFinished());
+ QCOMPARE(proc.exitCode(), 0);
+ QByteArray mocOut = proc.readAllStandardOutput();
+ QVERIFY(!mocOut.isEmpty());
+ QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ QCOMPARE(mocWarning, QString(SRCDIR) + QString("/pure-virtual-signals.h:48: Warning: Signals cannot be declared virtual\n") +
+ QString(SRCDIR) + QString("/pure-virtual-signals.h:50: Warning: Signals cannot be declared virtual\n"));
+#else
+ QSKIP("Only tested on linux/gcc", SkipAll);
+#endif
+}
+
QTEST_MAIN(tst_Moc)
#include "tst_moc.moc"