[libcxx-commits] [libcxx] [libc++][numeric] P4052R0: Renaming saturation arithmetic functions (PR #189574)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 31 07:24:08 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Hristo Hristov (H-G-Hristov)
<details>
<summary>Changes</summary>
Implements P4052R0.
Also renames:
- the internal names for consistency.
- test files (no changes to the contents but the function names).
Fixes: #<!-- -->189589
---
Patch is 115.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/189574.diff
26 Files Affected:
- (modified) libcxx/docs/FeatureTestMacroTable.rst (+1-1)
- (modified) libcxx/docs/ReleaseNotes/23.rst (+1)
- (modified) libcxx/include/__numeric/saturation_arithmetic.h (+15-15)
- (modified) libcxx/include/numeric (+5-5)
- (modified) libcxx/include/version (+2-2)
- (modified) libcxx/modules/std/numeric.inc (+5-5)
- (modified) libcxx/test/libcxx/numerics/nodiscard.verify.cpp (+5-5)
- (modified) libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp (+2-2)
- (modified) libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp (+2-2)
- (removed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp (-171)
- (removed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp (-155)
- (removed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.pass.cpp (-177)
- (removed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp (-394)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_add.compile.pass.cpp (+2-2)
- (added) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_add.pass.cpp (+171)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_cast.compile.pass.cpp (+2-2)
- (added) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_cast.pass.cpp (+394)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.assert.pass.cpp (+2-2)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.compile.pass.cpp (+3-3)
- (added) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_div.pass.cpp (+155)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_mul.compile.pass.cpp (+2-2)
- (added) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_mul.pass.cpp (+177)
- (renamed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.compile.pass.cpp (+2-2)
- (added) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturating_sub.pass.cpp (+159)
- (removed) libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.pass.cpp (-159)
- (modified) libcxx/utils/generate_feature_test_macro_components.py (+1-1)
``````````diff
diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index 0f65770a4fa14..32c17a51b77dd 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -508,7 +508,7 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_reference_wrapper`` ``202403L``
---------------------------------------------------------- -----------------
- ``__cpp_lib_saturation_arithmetic`` ``202311L``
+ ``__cpp_lib_saturation_arithmetic`` ``202603L``
---------------------------------------------------------- -----------------
``__cpp_lib_senders`` *unimplemented*
---------------------------------------------------------- -----------------
diff --git a/libcxx/docs/ReleaseNotes/23.rst b/libcxx/docs/ReleaseNotes/23.rst
index aeabfeedfbc5e..77d977149baf3 100644
--- a/libcxx/docs/ReleaseNotes/23.rst
+++ b/libcxx/docs/ReleaseNotes/23.rst
@@ -39,6 +39,7 @@ Implemented Papers
------------------
- P2440R1: ``ranges::iota``, ``ranges::shift_left`` and ``ranges::shift_right`` (`Github <https://llvm.org/PR105184>`__)
+- P4052R0: Renaming saturation arithmetic functions (`Github <https://llvm.org/PR189589>`__)
Improvements and New Features
-----------------------------
diff --git a/libcxx/include/__numeric/saturation_arithmetic.h b/libcxx/include/__numeric/saturation_arithmetic.h
index 4491bab2b1479..34f784e4a9cf1 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template <__signed_or_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_add(_Tp __x, _Tp __y) noexcept {
# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2101
return __builtin_elementwise_add_sat(__x, __y);
# else
@@ -51,7 +51,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
}
template <__signed_or_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_sub(_Tp __x, _Tp __y) noexcept {
# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2101
return __builtin_elementwise_sub_sat(__x, __y);
# else
@@ -74,7 +74,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
}
template <__signed_or_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_mul(_Tp __x, _Tp __y) noexcept {
if (_Tp __mul; !__builtin_mul_overflow(__x, __y, std::addressof(__mul)))
return __mul;
// Handle overflow
@@ -90,7 +90,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
}
template <__signed_or_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __saturating_div(_Tp __x, _Tp __y) noexcept {
_LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
if constexpr (__unsigned_integer<_Tp>) {
return __x / __y;
@@ -103,7 +103,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
}
template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturating_cast(_Tp __x) noexcept {
// Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max _Rp) > (max _Tp)) and it is expected to be
// optimized out by the compiler.
@@ -121,28 +121,28 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
#if _LIBCPP_STD_VER >= 26
template <__signed_or_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
- return std::__add_sat(__x, __y);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_add(_Tp __x, _Tp __y) noexcept {
+ return std::__saturating_add(__x, __y);
}
template <__signed_or_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
- return std::__sub_sat(__x, __y);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_sub(_Tp __x, _Tp __y) noexcept {
+ return std::__saturating_sub(__x, __y);
}
template <__signed_or_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
- return std::__mul_sat(__x, __y);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_mul(_Tp __x, _Tp __y) noexcept {
+ return std::__saturating_mul(__x, __y);
}
template <__signed_or_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
- return std::__div_sat(__x, __y);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp saturating_div(_Tp __x, _Tp __y) noexcept {
+ return std::__saturating_div(__x, __y);
}
template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
- return std::__saturate_cast<_Rp>(__x);
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturating_cast(_Tp __x) noexcept {
+ return std::__saturating_cast<_Rp>(__x);
}
#endif // _LIBCPP_STD_VER >= 26
diff --git a/libcxx/include/numeric b/libcxx/include/numeric
index 48c330fcb009c..64111b88d3538 100644
--- a/libcxx/include/numeric
+++ b/libcxx/include/numeric
@@ -142,15 +142,15 @@ template<class T>
// [numeric.sat], saturation arithmetic
template<class T>
-constexpr T add_sat(T x, T y) noexcept; // freestanding, Since C++26
+constexpr T saturating_add(T x, T y) noexcept; // freestanding, Since C++26
template<class T>
-constexpr T sub_sat(T x, T y) noexcept; // freestanding, Since C++26
+constexpr T saturating_sub(T x, T y) noexcept; // freestanding, Since C++26
template<class T>
-constexpr T mul_sat(T x, T y) noexcept; // freestanding, Since C++26
+constexpr T saturating_mul(T x, T y) noexcept; // freestanding, Since C++26
template<class T>
-constexpr T div_sat(T x, T y) noexcept; // freestanding, Since C++26
+constexpr T saturating_div(T x, T y) noexcept; // freestanding, Since C++26
template<class T, class U>
-constexpr T saturate_cast(U x) noexcept; // freestanding, Since C++26
+constexpr T saturating_cast(U x) noexcept; // freestanding, Since C++26
} // std
diff --git a/libcxx/include/version b/libcxx/include/version
index c43d36e569efb..286c8b654ff6b 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -227,7 +227,7 @@ __cpp_lib_remove_cvref 201711L <type_traits>
__cpp_lib_result_of_sfinae 201210L <functional> <type_traits>
__cpp_lib_robust_nonmodifying_seq_ops 201304L <algorithm>
__cpp_lib_sample 201603L <algorithm>
-__cpp_lib_saturation_arithmetic 202311L <numeric>
+__cpp_lib_saturation_arithmetic 202603L <numeric>
__cpp_lib_scoped_lock 201703L <mutex>
__cpp_lib_semaphore 201907L <semaphore>
__cpp_lib_senders 202406L <execution>
@@ -612,7 +612,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_ratio 202306L
// # define __cpp_lib_rcu 202306L
# define __cpp_lib_reference_wrapper 202403L
-# define __cpp_lib_saturation_arithmetic 202311L
+# define __cpp_lib_saturation_arithmetic 202603L
// # define __cpp_lib_senders 202406L
// # define __cpp_lib_smart_ptr_owner_equality 202306L
# define __cpp_lib_span_at 202311L
diff --git a/libcxx/modules/std/numeric.inc b/libcxx/modules/std/numeric.inc
index 5a549552081d2..e0edff9dfb0a5 100644
--- a/libcxx/modules/std/numeric.inc
+++ b/libcxx/modules/std/numeric.inc
@@ -61,11 +61,11 @@ export namespace std {
#if _LIBCPP_STD_VER >= 26
// [numeric.sat], saturation arithmetic
- using std::add_sat;
- using std::div_sat;
- using std::mul_sat;
- using std::saturate_cast;
- using std::sub_sat;
+ using std::saturating_add;
+ using std::saturating_cast;
+ using std::saturating_div;
+ using std::saturating_mul;
+ using std::saturating_sub;
#endif
} // namespace std
diff --git a/libcxx/test/libcxx/numerics/nodiscard.verify.cpp b/libcxx/test/libcxx/numerics/nodiscard.verify.cpp
index fe59e6a6a3fa7..c3635b8027aee 100644
--- a/libcxx/test/libcxx/numerics/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/numerics/nodiscard.verify.cpp
@@ -25,11 +25,11 @@ void test() {
// clang-format off
#if TEST_STD_VER >= 26
// [numeric.sat]
- std::add_sat(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::sub_sat(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::mul_sat(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::div_sat(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::saturate_cast<signed int>(49); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::saturating_add(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::saturating_sub(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::saturating_mul(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::saturating_div(94, 82); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::saturating_cast<signed int>(49); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
#endif // TEST_STD_VER >= 26
// clang-format on
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp
index cafbd2cac2ccf..d629407c9b645 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp
@@ -245,8 +245,8 @@
# ifndef __cpp_lib_saturation_arithmetic
# error "__cpp_lib_saturation_arithmetic should be defined in c++26"
# endif
-# if __cpp_lib_saturation_arithmetic != 202311L
-# error "__cpp_lib_saturation_arithmetic should have the value 202311L in c++26"
+# if __cpp_lib_saturation_arithmetic != 202603L
+# error "__cpp_lib_saturation_arithmetic should have the value 202603L in c++26"
# endif
#endif // TEST_STD_VER > 23
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index a1c8755af4ad9..718c67f11d00d 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -7782,8 +7782,8 @@
# ifndef __cpp_lib_saturation_arithmetic
# error "__cpp_lib_saturation_arithmetic should be defined in c++26"
# endif
-# if __cpp_lib_saturation_arithmetic != 202311L
-# error "__cpp_lib_saturation_arithmetic should have the value 202311L in c++26"
+# if __cpp_lib_saturation_arithmetic != 202603L
+# error "__cpp_lib_saturation_arithmetic should have the value 202603L in c++26"
# endif
# if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_THREADS
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp
deleted file mode 100644
index f49e19acf0234..0000000000000
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++26
-
-// <numeric>
-
-// template<class T>
-// constexpr T add_sat(T x, T y) noexcept; // freestanding
-
-#include <cassert>
-#include <concepts>
-#include <limits>
-#include <numeric>
-
-#include "test_macros.h"
-
-template <typename IntegerT>
-constexpr bool test_signed() {
- constexpr auto minVal = std::numeric_limits<IntegerT>::min();
- constexpr auto maxVal = std::numeric_limits<IntegerT>::max();
-
- std::same_as<IntegerT> decltype(auto) _ = std::add_sat(minVal, maxVal);
-
- static_assert(noexcept(std::add_sat(minVal, maxVal)));
-
- // clang-format off
-
- // Limit values (-1, 0, 1, min, max)
-
- assert(std::add_sat(IntegerT{-1}, IntegerT{-1}) == IntegerT{-2});
- assert(std::add_sat(IntegerT{-1}, IntegerT{ 0}) == IntegerT{-1});
- assert(std::add_sat(IntegerT{-1}, IntegerT{ 1}) == IntegerT{ 0});
- assert(std::add_sat(IntegerT{-1}, minVal) == minVal); // saturated
- assert(std::add_sat(IntegerT{-1}, maxVal) == IntegerT{-1} + maxVal);
-
- assert(std::add_sat(IntegerT{ 0}, IntegerT{-1}) == IntegerT{-1});
- assert(std::add_sat(IntegerT{ 0}, IntegerT{ 0}) == IntegerT{ 0});
- assert(std::add_sat(IntegerT{ 0}, IntegerT{ 1}) == IntegerT{ 1});
- assert(std::add_sat(IntegerT{ 0}, minVal) == minVal);
- assert(std::add_sat(IntegerT{ 0}, maxVal) == maxVal);
-
- assert(std::add_sat(IntegerT{ 1}, IntegerT{-1}) == IntegerT{ 0});
- assert(std::add_sat(IntegerT{ 1}, IntegerT{ 0}) == IntegerT{ 1});
- assert(std::add_sat(IntegerT{ 1}, IntegerT{ 1}) == IntegerT{ 2});
- assert(std::add_sat(IntegerT{ 1}, minVal) == IntegerT{ 1} + minVal);
- assert(std::add_sat(IntegerT{ 1}, maxVal) == maxVal); // saturated
-
- assert(std::add_sat( minVal, IntegerT{-1}) == minVal); // saturated
- assert(std::add_sat( minVal, IntegerT{ 0}) == minVal);
- assert(std::add_sat( minVal, IntegerT{ 1}) == minVal + IntegerT{ 1});
- assert(std::add_sat( minVal, minVal) == minVal); // saturated
- assert(std::add_sat( minVal, maxVal) == IntegerT{-1});
-
- assert(std::add_sat( maxVal, IntegerT{-1}) == maxVal + IntegerT{-1});
- assert(std::add_sat( maxVal, IntegerT{ 0}) == maxVal);
- assert(std::add_sat( maxVal, IntegerT{ 1}) == maxVal); // saturated
- assert(std::add_sat( maxVal, minVal) == IntegerT{-1});
- assert(std::add_sat( maxVal, maxVal) == maxVal); // saturated
-
- // No saturation (no limit values)
-
- assert(std::add_sat(IntegerT{-27}, IntegerT{28})== IntegerT{ 1});
- assert(std::add_sat(IntegerT{ 27}, IntegerT{28})== IntegerT{55});
- {
- constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{27};
- constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
- assert(std::add_sat(x, y) == maxVal);
- }
-
- // Saturation (no limit values)
-
- {
- constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-27};
- constexpr IntegerT y = minVal / IntegerT{2} + IntegerT{-28};
- assert(std::add_sat(x, y) == minVal); // saturated
- }
- {
- constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{27};
- constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
- assert(std::add_sat(x, y) == maxVal); // saturated
- }
-
- // clang-format on
-
- return true;
-}
-
-template <typename IntegerT>
-constexpr bool test_unsigned() {
- constexpr auto minVal = std::numeric_limits<IntegerT>::min();
- constexpr auto maxVal = std::numeric_limits<IntegerT>::max();
-
- std::same_as<IntegerT> decltype(auto) _ = std::add_sat(minVal, maxVal);
-
- static_assert(noexcept(std::add_sat(minVal, maxVal)));
-
- // clang-format off
-
- // Litmit values (0, 1, min, max)
-
- assert(std::add_sat(IntegerT{0}, IntegerT{0}) == IntegerT{0});
- assert(std::add_sat(IntegerT{0}, IntegerT{1}) == IntegerT{1});
- assert(std::add_sat(IntegerT{0}, minVal) == IntegerT{0});
- assert(std::add_sat(IntegerT{0}, maxVal) == maxVal);
- assert(std::add_sat(IntegerT{1}, IntegerT{0}) == IntegerT{1});
- assert(std::add_sat(IntegerT{1}, IntegerT{1}) == IntegerT{2});
- assert(std::add_sat(IntegerT{1}, minVal) == IntegerT{1});
- assert(std::add_sat(IntegerT{1}, maxVal) == maxVal); // saturated
- assert(std::add_sat( minVal, IntegerT{0}) == IntegerT{0});
- assert(std::add_sat( minVal, IntegerT{1}) == IntegerT{1});
- assert(std::add_sat( minVal, minVal) == minVal);
- assert(std::add_sat( minVal, maxVal) == maxVal);
- assert(std::add_sat( maxVal, IntegerT{0}) == maxVal);
- assert(std::add_sat( maxVal, IntegerT{1}) == maxVal); // saturated
- assert(std::add_sat( maxVal, minVal) == maxVal);
- assert(std::add_sat( maxVal, maxVal) == maxVal); // saturated
-
- // No saturation (no limit values)
-
- assert(std::add_sat(IntegerT{27}, IntegerT{28}) == IntegerT{55});
-
- // Saturation (no limit values)
-
- {
- constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{27};
- constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
- assert(std::add_sat( x, y) == maxVal); // saturated
- assert(std::add_sat( x, maxVal) == maxVal); // saturated
- assert(std::add_sat(maxVal, y) == maxVal); // saturated
- }
-
- // clang-format on
-
- return true;
-}
-
-constexpr bool test() {
- // Signed
- test_signed<signed char>();
- test_signed<short int>();
- test_signed<int>();
- test_signed<long int>();
- test_signed<long long int>();
-#ifndef TEST_HAS_NO_INT128
- test_signed<__int128_t>();
-#endif
- // Unsigned
- test_unsigned<unsigned char>();
- test_unsigned<unsigned short int>();
- test_unsigned<unsigned int>();
- test_unsigned<unsigned long int>();
- test_unsigned<unsigned long long int>();
-#ifndef TEST_HAS_NO_INT128
- test_unsigned<__uint128_t>();
-#endif
-
- return true;
-}
-
-int main(int, char**) {
- test();
- static_assert(test());
-
- return 0;
-}
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp
deleted file mode 100644
index 0789213163847..0000000000000
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++26
-
-// <numeric>
-
-// template<class T>
-// constexpr T div_sat(T x, T y) noexcept; // freestanding
-
-#include <cassert>
-#include <concepts>
-#include <limits>
-#include <numeric>
-
-#include "test_macros.h"
-
-template <typename IntegerT>
-constexpr bool test_signed() {
- constexpr auto minVal = std::numeric_limits<IntegerT>::min();
- constexpr auto maxVal = std::numeric_limits<IntegerT>::max();
-
- std:...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/189574
More information about the libcxx-commits
mailing list