Fix signedness errors from MSVC
authorMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 22:50:13 +0000 (01:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 22:55:23 +0000 (01:55 +0300)
source/strings/lexicalcast.cpp
source/strings/regex.cpp

index 1c1f72010cc49c6b55c9013b4fc5bd4fbd662d75..2c867b2ce0572b7489a7fb6c9e74013efb6b7804 100644 (file)
@@ -19,6 +19,14 @@ template<typename T>
 struct IsNegative<T, false>
 { static bool eval(T) { return false; } };
 
+template<typename T, bool f = is_signed<T>::value>
+struct Negate
+{ static T eval(T v) { return -v; } };
+
+template<typename T>
+struct Negate<T, false>
+{ static T eval(T v) { return (~v)+1; } };
+
 /* Helper to avoid errors about ambiguous function calls since there are no
 overloads of abs for unsigned types */
 template<typename T, bool f = is_signed<T>::value>
@@ -170,7 +178,7 @@ T str_to_int(const string &s, const Fmt &f)
        }
 
        if(neg)
-               result = -result;
+               result = Negate<T>::eval(result);
 
        return result;
 }
index 27361b038b168071cabd98aa45a37e37fb27d9cc..832cd85b110ac81d245af918375ddd24256727ef 100644 (file)
@@ -143,7 +143,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
                                        result += atom;
                                }
                                result += ND_JUMP;
-                               write_int<Offset>(-(atom.size()+jump_size), result);
+                               write_int<Offset>(-static_cast<Offset>(atom.size()+jump_size), result);
                        }
                        else if(repeat_max>repeat_min)
                        {