From 436e3dc4f961b4ea6c541d1fdf82e476ac10597c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 22 Nov 2012 10:31:14 +0100 Subject: 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 --- src/tools/moc/preprocessor.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index b49ab9c210..49700a0992 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -565,7 +565,6 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac const Macro ¯o = 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"); -- cgit v1.2.3