summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2022-03-31 19:07:39 +0300
committerAndreas Kling <kling@serenityos.org>2022-03-31 19:10:15 +0200
commit597ca68e2d9da78505693e7db4eef47271e2ca68 (patch)
treebabeb879e6ab9a1131fdce164b66b369c43fbf2c /Userland/Libraries/LibCpp
parent53c6c36fba1dc9f7920fa9028b300612106bc263 (diff)
downloadserenity-597ca68e2d9da78505693e7db4eef47271e2ca68.zip
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.
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r--Userland/Libraries/LibCpp/Preprocessor.cpp12
1 files 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::MacroCall> Preprocessor::parse_macro_call(Vector<Token> c
++token_index;
Vector<MacroCall::Argument> arguments;
- MacroCall::Argument current_argument;
+ Optional<MacroCall::Argument> current_argument;
size_t paren_depth = 1;
for (; token_index < tokens.size(); ++token_index) {
@@ -288,15 +288,19 @@ Optional<Preprocessor::MacroCall> Preprocessor::parse_macro_call(Vector<Token> 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);
}
}