Parser.hpp: Fix a segmentation fault happening when parseTree is empty

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-08-28 10:51:35 +02:00
parent 94e71ef61e
commit 23f24e55b1
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 15 additions and 13 deletions

View File

@ -149,6 +149,7 @@ namespace Parser {
} catch (const NamedIdentifier<true>::identifier_reserved_exception&) { } catch (const NamedIdentifier<true>::identifier_reserved_exception&) {
parsingError(current, " is a reserved identifier", true); parsingError(current, " is a reserved identifier", true);
} }
if (not parseTree.empty()) {
const auto& last = parseTree.cend() - 1; const auto& last = parseTree.cend() - 1;
const type_info& lastId = last->get()->getId(); const type_info& lastId = last->get()->getId();
const auto* last_identifier = dynamic_cast<NamedIdentifier<true>*>(last->get()); const auto* last_identifier = dynamic_cast<NamedIdentifier<true>*>(last->get());
@ -164,6 +165,7 @@ namespace Parser {
{ parsingError(current, " has already been defined previously", true); } { parsingError(current, " has already been defined previously", true); }
} }
} }
}
return parseTree; return parseTree;
} }
template<derived_from<ParseTree> T> template<derived_from<ParseTree> T>