From 63b24752d67184be9505d4a91203b79fdb0fb141 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 12 Feb 2022 20:35:06 +0100 Subject: [PATCH] Make the members of the tok structure non-const to avoid undefined behaviour when the "=" operator is called Signed-off-by: Username404 --- src/headers/lex.hpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/headers/lex.hpp b/src/headers/lex.hpp index 635b4be..4a8903d 100644 --- a/src/headers/lex.hpp +++ b/src/headers/lex.hpp @@ -20,17 +20,9 @@ struct tok { static auto inverseLCharacter(const unsigned char& character) { return static_cast(((character + 2) - (character == tok::LPAR))); }; - const type toktype; - const std::string toktext; - const unsigned long line; - tok& operator=(const tok& other) { - if (this != &other) { - const_cast(toktype) = other.toktype; - const_cast(toktext) = other.toktext; - const_cast(line) = other.line; - } - return *this; - } + type toktype; + std::string toktext; + unsigned long line; tok(): toktype(UNEXPECTED), toktext(), line(0) {}; tok(const type& Type, std::string_view Text, const decltype(line)& line = 0): toktype(Type), toktext(Text), line(line) {} explicit tok(const type& Type, const decltype(line)& line = 0): tok(Type, std::string(1, Type), line) {};