summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-03-16 18:45:51 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-16 18:59:19 +0100
commit6c8185151e564a79c696f24583aac4eafd3bcf04 (patch)
tree657e5881bdf8b439d1bf9f4f41d60eb23ac9165b /Userland/Libraries/LibCpp
parent8e84ca6b165d6a42c6f93db2b54d18599fc7a03e (diff)
downloadserenity-6c8185151e564a79c696f24583aac4eafd3bcf04.zip
LibCpp: Return empty TranslationUnit from Parser::parse() if no tokens exist
Fixes #5704. Fixes #5825. Fixes #5827.
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r--Userland/Libraries/LibCpp/Parser.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp
index d8411713a7..f968686c46 100644
--- a/Userland/Libraries/LibCpp/Parser.cpp
+++ b/Userland/Libraries/LibCpp/Parser.cpp
@@ -75,6 +75,8 @@ void Parser::initialize_program_tokens(const StringView& program)
NonnullRefPtr<TranslationUnit> Parser::parse()
{
SCOPE_LOGGER();
+ if (m_tokens.is_empty())
+ return create_root_ast_node({}, {});
auto unit = create_root_ast_node(m_tokens.first().start(), m_tokens.last().end());
while (!done()) {
if (match_comment()) {