diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 32c94639ab..9a06fb38d0 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -1109,19 +1109,18 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) } case PP_DEFINE: { - next(IDENTIFIER); + next(); QByteArray name = lexem(); + if (name.isEmpty() || !is_ident_start(name[0])) + error(); Macro macro; macro.isVariadic = false; - Token t = next(); - if (t == LPAREN) { + if (test(LPAREN)) { // we have a function macro macro.isFunction = true; parseDefineArguments(¯o); - } else if (t == PP_WHITESPACE){ - macro.isFunction = false; } else { - error("Moc: internal error"); + macro.isFunction = false; } int start = index; until(PP_NEWLINE); @@ -1160,7 +1159,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) continue; } case PP_UNDEF: { - next(IDENTIFIER); + next(); QByteArray name = lexem(); until(PP_NEWLINE); macros.remove(name); diff --git a/tests/auto/tools/moc/parse-defines.h b/tests/auto/tools/moc/parse-defines.h index 6100bf67ad..7b0fa29d7c 100644 --- a/tests/auto/tools/moc/parse-defines.h +++ b/tests/auto/tools/moc/parse-defines.h @@ -146,6 +146,15 @@ signals: #undef QString +#ifdef Q_MOC_RUN +// Normaly, redefining keywords is forbidden, but we should not abort parsing +#define and && +#define and_eq &= +#define bitand & +#define true 1 +#undef true +#endif + PD_END_NAMESPACE #endif