diff --git a/peglib.h b/peglib.h index e6ae30f..6377d5c 100644 --- a/peglib.h +++ b/peglib.h @@ -496,6 +496,8 @@ struct SemanticValues : protected std::vector { // Line number and column at which the matched string is std::pair line_info() const { + if (!c_) { return std::pair(1, 1); } + auto &idx = source_line_index(); auto cur = static_cast(std::distance(ss, sv_.data())); @@ -2571,7 +2573,7 @@ inline size_t parse_literal(const char *s, size_t n, SemanticValues &vs, } inline const std::vector &SemanticValues::source_line_index() const { - if (!c_) { std::vector(); } + assert(c_); if (c_->source_line_index.empty()) { for (size_t pos = 0; pos < c_->l; pos++) { if (c_->s[pos] == '\n') { c_->source_line_index.push_back(pos); }