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
11 // REQUIRES: has-unix-headers
12 // REQUIRES: libcpp-hardening-mode={{extensive|debug}}
13 // XFAIL: availability-verbose_abort-missing
18 // constexpr T div_sat(T x, T y) noexcept; // freestanding
23 #include "check_assertion.h"
24 #include "test_macros.h"
26 template <typename IntegerT
>
27 void test_runtime_assertion() {
28 TEST_LIBCPP_ASSERT_FAILURE((void)std::div_sat(IntegerT
{27}, IntegerT
{0}), "Division by 0 is undefined");
33 test_runtime_assertion
<signed char>();
34 test_runtime_assertion
<short int>();
35 test_runtime_assertion
<int>();
36 test_runtime_assertion
<long int>();
37 test_runtime_assertion
<long long int>();
38 #ifndef TEST_HAS_NO_INT128
39 test_runtime_assertion
<__int128_t
>();
42 test_runtime_assertion
<unsigned char>();
43 test_runtime_assertion
<unsigned short int>();
44 test_runtime_assertion
<unsigned int>();
45 test_runtime_assertion
<unsigned long int>();
46 test_runtime_assertion
<unsigned long long int>();
47 #ifndef TEST_HAS_NO_INT128
48 test_runtime_assertion
<__uint128_t
>();
54 int main(int, char**) {