Skip to content

Commit

Permalink
moc: Don't error out when defining a keyword
Browse files Browse the repository at this point in the history
Normaly, in C++ It's not valid to define a keyword, but it turns out that some
system header do, so we just silently accept it.

[ChangeLog][moc] moc no longer errors out if a C++ keyword is #define'ed

Task-number: QTBUG-61204
Change-Id: Ia4d3ff9c77b6ff261b6140c220cfb81bd13f1d6d
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Simon Hausmann <[email protected]>
  • Loading branch information
ogoffart authored and thiagomacieira committed Jun 6, 2017
1 parent 74111ce commit 94a2aec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/tools/moc/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(&macro);
} else if (t == PP_WHITESPACE){
macro.isFunction = false;
} else {
error("Moc: internal error");
macro.isFunction = false;
}
int start = index;
until(PP_NEWLINE);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions tests/auto/tools/moc/parse-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ public slots:

#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

0 comments on commit 94a2aec

Please sign in to comment.