diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 7a7448b..3020ad5 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -149,19 +149,21 @@ namespace Parser { } catch (const NamedIdentifier::identifier_reserved_exception&) { parsingError(current, " is a reserved identifier", true); } - const auto& last = parseTree.cend() - 1; - const type_info& lastId = last->get()->getId(); - const auto* last_identifier = dynamic_cast*>(last->get()); - if (last_identifier != nullptr) { - if (lastId != typeid(Define) and - any_of(parseTree.cbegin(), last, [&last_identifier](const component_ptr& pointer){ - try { - return dynamic_cast&>(*pointer).name == last_identifier->name; - } catch (const bad_cast&) { - return false; - } - })) - { parsingError(current, " has already been defined previously", true); } + if (not parseTree.empty()) { + const auto& last = parseTree.cend() - 1; + const type_info& lastId = last->get()->getId(); + const auto* last_identifier = dynamic_cast*>(last->get()); + if (last_identifier != nullptr) { + if (lastId != typeid(Define) and + any_of(parseTree.cbegin(), last, [&last_identifier](const component_ptr& pointer){ + try { + return dynamic_cast&>(*pointer).name == last_identifier->name; + } catch (const bad_cast&) { + return false; + } + })) + { parsingError(current, " has already been defined previously", true); } + } } } return parseTree;