From 016300c064684fba81605a0d48ef14139c562722 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 7 Nov 2021 20:33:07 +0000 Subject: [PATCH] keep hold of offset in LocatedParseError --- src/parser/parse_error.cpp | 9 +++++---- src/parser/parse_error.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/parser/parse_error.cpp b/src/parser/parse_error.cpp index e7f60b264..698c06916 100644 --- a/src/parser/parse_error.cpp +++ b/src/parser/parse_error.cpp @@ -43,14 +43,15 @@ ParseError::~ParseError() {} LocatedParseError::~LocatedParseError() {} -void LocatedParseError::locate(size_t offset) { - if (finalized) { +void LocatedParseError::locate(size_t offset_) { + if (hasOffset) { return; } std::ostringstream str; - str << reason << " at index " << offset << "."; + str << reason << " at index " << offset_ << "."; reason = str.str(); - finalized = true; + offset = offset_; + hasOffset = true; } } diff --git a/src/parser/parse_error.h b/src/parser/parse_error.h index 4556ed5e0..ce846e5c6 100644 --- a/src/parser/parse_error.h +++ b/src/parser/parse_error.h @@ -58,8 +58,8 @@ class LocatedParseError : public ParseError { ~LocatedParseError() override; void locate(size_t offset); -private: - bool finalized = false; //!< true when locate() has been called. + bool hasOffset = false; //!< true when locate() has been called. + size_t offset; }; } // namespace ue2