1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
14 // constexpr T sub_sat(T x, T y) noexcept; // freestanding
19 #include "test_macros.h"
21 template <typename T
, typename U
>
22 concept CanDo
= requires(T x
, U y
) {
23 { std::sub_sat(x
, y
) } -> std::same_as
<T
>;
26 template <typename T
, typename U
>
27 constexpr void test_constraint_success() {
28 static_assert(CanDo
<T
, T
>);
29 static_assert(!CanDo
<U
, T
>);
30 static_assert(!CanDo
<T
, U
>);
34 constexpr void test_constraint_fail() {
36 static_assert(!CanDo
<T
, T
>);
37 static_assert(!CanDo
<I
, T
>);
38 static_assert(!CanDo
<T
, I
>);
41 constexpr void test() {
42 // Contraint success - Signed
43 using SI
= long long int;
44 test_constraint_success
<signed char, SI
>();
45 test_constraint_success
<short int, SI
>();
46 test_constraint_success
<signed char, SI
>();
47 test_constraint_success
<short int, SI
>();
48 test_constraint_success
<int, SI
>();
49 test_constraint_success
<long int, SI
>();
50 test_constraint_success
<long long int, int>();
51 #ifndef TEST_HAS_NO_INT128
52 test_constraint_success
<__int128_t
, SI
>();
54 // Contraint success - Unsigned
55 using UI
= unsigned long long int;
56 test_constraint_success
<unsigned char, UI
>();
57 test_constraint_success
<unsigned short int, UI
>();
58 test_constraint_success
<unsigned int, UI
>();
59 test_constraint_success
<unsigned long int, UI
>();
60 test_constraint_success
<unsigned long long int, unsigned int>();
61 #ifndef TEST_HAS_NO_INT128
62 test_constraint_success
<__uint128_t
, UI
>();
66 test_constraint_fail
<bool>();
67 test_constraint_fail
<char>();
68 #ifndef TEST_HAS_NO_INT128
69 test_constraint_fail
<wchar_t>();
71 test_constraint_fail
<char8_t
>();
72 test_constraint_fail
<char16_t
>();
73 test_constraint_fail
<char32_t
>();
74 test_constraint_fail
<float>();
75 test_constraint_fail
<double>();
76 test_constraint_fail
<long double>();