1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9// REQUIRES: std-at-least-c++26
10
11// REQUIRES: has-unix-headers
12// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
13// XFAIL: availability-verbose_abort-missing
14
15// <numeric>
16
17// template<class T>
18// constexpr T div_sat(T x, T y) noexcept; // freestanding
19
20#include <cassert>
21#include <numeric>
22
23#include "check_assertion.h"
24#include "test_macros.h"
25
26template <typename IntegerT>
27void test_runtime_assertion() {
28 TEST_LIBCPP_ASSERT_FAILURE((void)std::div_sat(IntegerT{27}, IntegerT{0}), "Division by 0 is undefined");
29}
30
31bool test() {
32 // Signed
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>();
40#endif
41 // Unsigned
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>();
49#endif
50
51 return true;
52}
53
54int main(int, char**) {
55 test();
56
57 return 0;
58}
59

source code of libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.assert.pass.cpp