From 597ca68e2d9da78505693e7db4eef47271e2ca68 Mon Sep 17 00:00:00 2001 From: Itamar Date: Thu, 31 Mar 2022 19:07:39 +0300 Subject: [PATCH] LibCpp: Fix parsing of macro calls Previously, macro calls with 0 arguments where incorrectly parsed as calls to a macro with a single argument that doesn't contain any tokens. --- Userland/Libraries/LibCpp/Preprocessor.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp index b8da494a6e..330bef1e14 100644 --- a/Userland/Libraries/LibCpp/Preprocessor.cpp +++ b/Userland/Libraries/LibCpp/Preprocessor.cpp @@ -277,7 +277,7 @@ Optional Preprocessor::parse_macro_call(Vector c ++token_index; Vector arguments; - MacroCall::Argument current_argument; + Optional current_argument; size_t paren_depth = 1; for (; token_index < tokens.size(); ++token_index) { @@ -288,15 +288,19 @@ Optional Preprocessor::parse_macro_call(Vector c --paren_depth; if (paren_depth == 0) { - arguments.append(move(current_argument)); + if (current_argument.has_value()) + arguments.append(*current_argument); break; } if (paren_depth == 1 && token.type() == Token::Type::Comma) { - arguments.append(move(current_argument)); + if (current_argument.has_value()) + arguments.append(*current_argument); current_argument = {}; } else { - current_argument.tokens.append(token); + if (!current_argument.has_value()) + current_argument = MacroCall::Argument {}; + current_argument->tokens.append(token); } }