moc: parse properly the gcc extension for variadic macro

Task-number: QTBUG-27547

Change-Id: I983b96b09c405e5330327092e56164b9921a2d0f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Olivier Goffart 2012-10-12 13:37:21 +02:00 committed by The Qt Project
parent 289a814778
commit 21426f281e
3 changed files with 30 additions and 2 deletions

View File

@ -1201,8 +1201,18 @@ void Preprocessor::parseDefineArguments(Macro *m)
t = next(); t = next();
if (t == PP_RPAREN) if (t == PP_RPAREN)
break; break;
if (t != PP_COMMA) if (t == PP_COMMA)
error("Unexpected character in macro argument list."); continue;
if (lexem() == "...") {
//GCC extension: #define FOO(x, y...) x(y)
// The last argument was already parsed. Just mark the macro as variadic.
m->isVariadic = true;
while (test(PP_WHITESPACE));
if (!test(PP_RPAREN))
error("missing ')' in macro argument list");
break;
}
error("Unexpected character in macro argument list.");
} }
m->arguments = arguments; m->arguments = arguments;
while (test(PP_WHITESPACE)); while (test(PP_WHITESPACE));

View File

@ -65,6 +65,14 @@
#if defined(Q_COMPILER_VARIADIC_MACROS) #if defined(Q_COMPILER_VARIADIC_MACROS)
#define PD_VARARG(x, ...) x(__VA_ARGS__) #define PD_VARARG(x, ...) x(__VA_ARGS__)
#if defined(Q_CC_GNU) || defined(Q_MOC_RUN)
//GCC extension for variadic macros
#define PD_VARARGEXT(x, y...) x(y)
#else
#define PD_VARARGEXT(x, ...) x(__VA_ARGS__)
#endif
#endif #endif
PD_BEGIN_NAMESPACE PD_BEGIN_NAMESPACE
@ -95,6 +103,10 @@ public slots:
PD_VARARG(void vararg1) {} PD_VARARG(void vararg1) {}
PD_VARARG(void vararg2, int) {} PD_VARARG(void vararg2, int) {}
PD_VARARG(void vararg3, int, int) {} PD_VARARG(void vararg3, int, int) {}
PD_VARARGEXT(void vararg4) {}
PD_VARARGEXT(void vararg5, int) {}
PD_VARARGEXT(void vararg6, int, int) {}
#endif #endif
}; };

View File

@ -2744,6 +2744,12 @@ void tst_Moc::parseDefines()
QVERIFY(index != -1); QVERIFY(index != -1);
index = mo->indexOfSlot("vararg3(int,int)"); index = mo->indexOfSlot("vararg3(int,int)");
QVERIFY(index != -1); QVERIFY(index != -1);
index = mo->indexOfSlot("vararg4()");
QVERIFY(index != -1);
index = mo->indexOfSlot("vararg5(int)");
QVERIFY(index != -1);
index = mo->indexOfSlot("vararg6(int,int)");
QVERIFY(index != -1);
#endif #endif
int count = 0; int count = 0;