Skip to content

Commit 2c78fd5

Browse files
committed
AK: Remove unused Checked<T> code
We could never hit the #else branches for some of these methods, because we already relied on having __builtin_*_overflow() readily available in earlier methods. multiplication_would_overflow() with three arguments was only used in a test, so let's get rid of that as well.
1 parent f49cf75 commit 2c78fd5

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

AK/Checked.h

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,9 @@ class Checked {
348348
{
349349
#if __has_builtin(__builtin_add_overflow_p)
350350
return __builtin_add_overflow_p(u, v, (T)0);
351-
#elif __has_builtin(__builtin_add_overflow)
351+
#else
352352
T result;
353353
return __builtin_add_overflow(u, v, &result);
354-
#else
355-
Checked checked;
356-
checked = u;
357-
checked += v;
358-
return checked.has_overflow();
359354
#endif
360355
}
361356

@@ -364,14 +359,9 @@ class Checked {
364359
{
365360
#if __has_builtin(__builtin_sub_overflow_p)
366361
return __builtin_sub_overflow_p(u, v, (T)0);
367-
#elif __has_builtin(__builtin_sub_overflow)
362+
#else
368363
T result;
369364
return __builtin_sub_overflow(u, v, &result);
370-
#else
371-
Checked checked;
372-
checked = u;
373-
checked -= v;
374-
return checked.has_overflow();
375365
#endif
376366
}
377367

@@ -404,27 +394,12 @@ class Checked {
404394
{
405395
#if __has_builtin(__builtin_mul_overflow_p)
406396
return __builtin_mul_overflow_p(u, v, (T)0);
407-
#elif __has_builtin(__builtin_mul_overflow)
397+
#else
408398
T result;
409399
return __builtin_mul_overflow(u, v, &result);
410-
#else
411-
Checked checked;
412-
checked = u;
413-
checked *= v;
414-
return checked.has_overflow();
415400
#endif
416401
}
417402

418-
template<typename U, typename V, typename X>
419-
[[nodiscard]] static constexpr bool multiplication_would_overflow(U u, V v, X x)
420-
{
421-
Checked checked;
422-
checked = u;
423-
checked *= v;
424-
checked *= x;
425-
return checked.has_overflow();
426-
}
427-
428403
private:
429404
T m_value {};
430405
bool m_overflow { false };

Tests/AK/TestChecked.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ TEST_CASE(should_constexpr_check_for_overflow_addition)
374374
TEST_CASE(should_constexpr_check_for_overflow_multiplication)
375375
{
376376
static_assert(Checked<int>::multiplication_would_overflow(NumericLimits<int>::max(), 2));
377-
static_assert(Checked<int>::multiplication_would_overflow(NumericLimits<int>::max(), 1, 2));
378377
}
379378

380379
TEST_CASE(should_constexpr_add_checked_values)

0 commit comments

Comments
 (0)