brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 50bc29b Raw
59 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: std-at-least-c++2610 11// REQUIRES: has-unix-headers12// REQUIRES: libcpp-hardening-mode={{extensive|debug}}13// XFAIL: availability-verbose_abort-missing14 15// <numeric>16 17// template<class T>18// constexpr T div_sat(T x, T y) noexcept;                     // freestanding19 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  // Signed33  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_INT12839  test_runtime_assertion<__int128_t>();40#endif41  // Unsigned42  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_INT12848  test_runtime_assertion<__uint128_t>();49#endif50 51  return true;52}53 54int main(int, char**) {55  test();56 57  return 0;58}59