moc: Issue a warning instead of an error when macro argument mismatch
moc's C++ is not 100% accurate, so better process the invalid macro with a warning rather than an error. Such errors occurred in the QSKIP macro with variadic arguments since that macro is defined conditionally. It is also causing problem in boost header (cf task QTBUG-29331) Task-number: QTBUG-29331 Change-Id: Ice6a01b675286540d6470c8e36920b7efd39b540 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
95e880bd9d
commit
c20b358703
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user