From 9d8404871097ceedb84818cef26c6833dea936e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 26 Jul 2022 15:52:12 +0200 Subject: [PATCH] Bytecode MEX: fix bug introduced in 8c01912a50f832d1303e41ffad1a5136a1f1d062 Use an iterator wrapped inside std::optional instead of a possibly-singular iterator, because the latter has undefined behaviour. By the way, pass arguments by const reference. --- mex/sources/bytecode/ErrorHandling.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh index 35d48bfa1e..83ec6136ad 100644 --- a/mex/sources/bytecode/ErrorHandling.hh +++ b/mex/sources/bytecode/ErrorHandling.hh @@ -29,6 +29,7 @@ #include <sstream> #include <iostream> #include <stack> +#include <optional> #define _USE_MATH_DEFINES #include <cmath> @@ -407,7 +408,7 @@ protected: corresponding mathematical operator will be printed within braces. The second output argument points to the tag past the expression. */ pair<string, it_code_type> - print_expression(it_code_type expr_begin, it_code_type faulty_op = {}) const + print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const { int var, lag{0}, eq; UnaryOpcode op1; -- GitLab