Split two error cases so they get reported distinctly.

If a macro is used with too few parameters, complaining about its
definition using '#' followed by something other than a macro
parameter name is apt to be confusing - reading the definition will
reveal that the name in fact is a macro parameter after all.  The
reader needs attention directed to the invocation, not the definition.

Split the test in two: one to test the prior error message does in
fact get produced for an invalid macro definition, the other to test
the invalid invocation case.

Task-number: QTBUG-46210
Change-Id: Ie177a56d346e553bf9d67e2008a4352633afa1ae
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Edward Welbourne 2015-10-12 10:41:21 +02:00
parent dde8d5e3a0
commit 1901adbab7
2 changed files with 13 additions and 3 deletions

View File

@ -658,9 +658,12 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
expansion += s; expansion += s;
} }
} else if (mode == Hash) { } else if (mode == Hash) {
if (index < 0 || index >= arguments.size()) { if (index < 0) {
that->error("'#' is not followed by a macro parameter"); that->error("'#' is not followed by a macro parameter");
continue; continue;
} else if (index >= arguments.size()) {
that->error("Macro invoked with too few parameters for a use of '#'");
continue;
} }
const Symbols &arg = arguments.at(index); const Symbols &arg = arguments.at(index);

View File

@ -1883,12 +1883,19 @@ void tst_Moc::warnings_data()
<< QString() << QString()
<< QString("standard input:5: Error: Class declaration lacks Q_OBJECT macro."); << QString("standard input:5: Error: Class declaration lacks Q_OBJECT macro.");
QTest::newRow("QTBUG-46210: crash on invalid macro") QTest::newRow("Invalid macro definition")
<< QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c #d\n Foo(45);") << QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c #d\n Foo(45, 42, 39);")
<< QStringList() << QStringList()
<< 1 << 1
<< QString("IGNORE_ALL_STDOUT") << QString("IGNORE_ALL_STDOUT")
<< QString(":2: Error: '#' is not followed by a macro parameter"); << QString(":2: Error: '#' is not followed by a macro parameter");
QTest::newRow("QTBUG-46210: crash on invalid macro invocation")
<< QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c\n Foo(45);")
<< QStringList()
<< 1
<< QString("IGNORE_ALL_STDOUT")
<< QString(":2: Error: Macro invoked with too few parameters for a use of '#'");
} }
void tst_Moc::warnings() void tst_Moc::warnings()