Skip to content

Commit a65b745

Browse files
committed
trying to fix clang msvc issue
1 parent f01048b commit a65b745

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

include/pythonic/pythonicOverflow.hpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,50 +126,59 @@ namespace pythonic
126126
template <Integral T>
127127
constexpr bool would_add_overflow(T a, T b) noexcept
128128
{
129-
#ifdef _MSC_VER
129+
#ifdef _MSC_VER
130130
T res = a + b;
131-
if constexpr (std::is_signed_v<T>) {
131+
if constexpr (std::is_signed_v<T>)
132+
{
132133
return ((a > 0 && b > 0 && res < 0) || (a < 0 && b < 0 && res > 0));
133-
} else {
134+
}
135+
else
136+
{
134137
return res < a;
135138
}
136-
#else
139+
#else
137140
T res;
138141
return __builtin_add_overflow(a, b, &res);
139-
#endif
142+
#endif
140143
}
141144

142145
template <Integral T>
143146
constexpr bool would_sub_overflow(T a, T b) noexcept
144147
{
145-
#ifdef _MSC_VER
148+
#ifdef _MSC_VER
146149
T res = a - b;
147-
if constexpr (std::is_signed_v<T>) {
150+
if constexpr (std::is_signed_v<T>)
151+
{
148152
return ((a > 0 && b < 0 && res < 0) || (a < 0 && b > 0 && res > 0));
149-
} else {
153+
}
154+
else
155+
{
150156
return res > a;
151157
}
152-
#else
158+
#else
153159
T res;
154160
return __builtin_sub_overflow(a, b, &res);
155-
#endif
161+
#endif
156162
}
157163

158164
template <Integral T>
159165
constexpr bool would_mul_overflow(T a, T b) noexcept
160166
{
161-
#ifdef _MSC_VER
167+
#ifdef _MSC_VER
162168
T res = a * b;
163-
if constexpr (std::is_signed_v<T>) {
169+
if constexpr (std::is_signed_v<T>)
170+
{
164171
bool same_sign = (a >= 0) == (b >= 0);
165172
return (same_sign && res < 0) || (!same_sign && res > 0);
166-
} else {
173+
}
174+
else
175+
{
167176
return (a != 0 && b > std::numeric_limits<T>::max() / a);
168177
}
169-
#else
178+
#else
170179
T res;
171180
return __builtin_mul_overflow(a, b, &res);
172-
#endif
181+
#endif
173182
}
174183

175184
// Floating point doesn't have traditional overflow, but we can check for infinity

0 commit comments

Comments
 (0)