Correctly expand arguments in function macros

Arguments in function macros are only expanded if they
aren't used in conjunction with a # or ## operator.

Change-Id: I8c80e11902a592128504c4637545e75866566965
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
bb10
Lars Knoll 2012-11-22 10:31:14 +01:00 committed by The Qt Project
parent 863e44a42b
commit 436e3dc4f9
1 changed files with 12 additions and 11 deletions

View File

@ -565,7 +565,6 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac
const Macro &macro = macros.value(s);
safeset += s;
// don't expand macros with arguments for now
if (macro.isFunction) {
while (test(PP_WHITESPACE)) {}
if (!test(PP_LPAREN)) {
@ -593,11 +592,7 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac
}
argument += symbol();
}
// each argument undoergoes macro expansion
Symbols expanded;
macroExpandSymbols(lineNum, argument, expanded, safeset);
arguments += expanded;
arguments += argument;
if (nesting < 0)
break;
@ -630,13 +625,19 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac
}
int index = macro.arguments.indexOf(s);
if (mode == Normal) {
if (index >= 0)
expansion += arguments.at(index);
else
if (index >= 0) {
// 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 expanded;
macroExpandSymbols(lineNum, arguments.at(index), expanded, safeset);
expansion += expanded;
} else {
expansion += arguments.at(index);
}
} else {
expansion += s;
}
} else if (mode == Hash) {
if (s.token == WHITESPACE)
continue;
if (index < 0)
error("'#' is not followed by a macro parameter");