summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/moc/preprocessor.cpp4
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp10
2 files changed, 11 insertions, 3 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 8f4b84a9c8..06758e67bd 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -645,7 +645,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
// 0 argument macros are a bit special. They are ok if the
// argument is pure whitespace or empty
(macro.arguments.size() != 0 || arguments.size() != 1 || !arguments.at(0).isEmpty()))
- that->error("Macro argument mismatch.");
+ that->warning("Macro argument mismatch.");
// now replace the macro arguments with the expanded arguments
enum Mode {
@@ -662,7 +662,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
}
int index = macro.arguments.indexOf(s);
if (mode == Normal) {
- if (index >= 0) {
+ if (index >= 0 && index < arguments.size()) {
// each argument undoergoes macro expansion if it's not used as part of a # or ##
if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) {
Symbols arg = arguments.at(index);
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 3459bede85..612ce3cd7e 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -1718,6 +1718,14 @@ void tst_Moc::warnings_data()
<< 1
<< QString()
<< QString("standard input:1: Error: Class contains Q_OBJECT macro but does not inherit from QObject");
+
+ QTest::newRow("Warning on invalid macro")
+ << QByteArray("#define Foo(a, b)\n class X : public QObject { Q_OBJECT }; \n Foo(a) \n Foo(a,b,c) \n")
+ << QStringList()
+ << 0
+ << QString("IGNORE_ALL_STDOUT")
+ << QString(":3: Warning: Macro argument mismatch.\n:4: Warning: Macro argument mismatch.");
+
}
void tst_Moc::warnings()
@@ -1759,7 +1767,7 @@ void tst_Moc::warnings()
// magic value "IGNORE_ALL_STDOUT" ignores stdout
if (expectedStdOut != "IGNORE_ALL_STDOUT")
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardOutput()).trimmed(), expectedStdOut);
- QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()).trimmed(), expectedStdErr);
+ QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()).trimmed().remove('\r'), expectedStdErr);
}
class tst_Moc::PrivateClass : public QObject {