Commit 449a8030 by Corentin Wallez Committed by Commit Bot

MacroExpander: bump expansionCount before peeking for "("

BUG=658555 Change-Id: I578b8aff37a116fd7b2b387388311a27bb8a2809 Reviewed-on: https://chromium-review.googlesource.com/403848Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 79a92bea
...@@ -87,10 +87,15 @@ void MacroExpander::lex(Token *token) ...@@ -87,10 +87,15 @@ void MacroExpander::lex(Token *token)
token->setExpansionDisabled(true); token->setExpansionDisabled(true);
break; break;
} }
// Bump the expansion count before peeking if the next token is a '('
// otherwise there could be a #undef of the macro before the next token.
macro.expansionCount++;
if ((macro.type == Macro::kTypeFunc) && !isNextTokenLeftParen()) if ((macro.type == Macro::kTypeFunc) && !isNextTokenLeftParen())
{ {
// If the token immediately after the macro name is not a '(', // If the token immediately after the macro name is not a '(',
// this macro should not be expanded. // this macro should not be expanded.
macro.expansionCount--;
break; break;
} }
...@@ -157,8 +162,6 @@ bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier) ...@@ -157,8 +162,6 @@ bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier)
ASSERT(identifier.type == Token::IDENTIFIER); ASSERT(identifier.type == Token::IDENTIFIER);
ASSERT(identifier.text == macro.name); ASSERT(identifier.text == macro.name);
macro.expansionCount++;
std::vector<Token> replacements; std::vector<Token> replacements;
if (!expandMacro(macro, identifier, &replacements)) if (!expandMacro(macro, identifier, &replacements))
return false; return false;
......
...@@ -955,3 +955,19 @@ TEST_F(DefineTest, UndefineInInvocation) ...@@ -955,3 +955,19 @@ TEST_F(DefineTest, UndefineInInvocation)
preprocess(input, expected); preprocess(input, expected);
} }
// Undefining a macro before its invocation parameters produces and error
TEST_F(DefineTest, UndefineInInvocationPreLParen)
{
const char *input =
"#define G(a, b) a b\n"
"G\n"
"#undef G\n"
"(1, 2)\n";
const char *expected = "\n\n\n1 2\n";
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_MACRO_UNDEFINED_WHILE_INVOKED,
pp::SourceLocation(0, 3), _));
preprocess(input, expected);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment