[libcxx-commits] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 13 05:24:45 PST 2024


================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <numeric>
+
+// template<class T>
+// constexpr T add_sat(T x, T y) noexcept;                     // freestanding
+
+#include <cstdint>
+#include <numeric>
+
+#include "test_macros.h"
+
+template <typename IntegerT>
+constexpr void test_constraint() {
+  // expected-error-re@*:* 0-2 {{constant expression evaluates to {{.*}} which cannot be narrowed to type {{.*}}}}
+  // expected-error@*:* 0-3 {{no matching function for call to 'add_sat'}}
+  // expected-error@*:* 0-2 {{expected unqualified-id}}
+  [[maybe_unused]] auto sum = std::add_sat(IntegerT{3}, IntegerT{4});
+}
+
+constexpr bool test() {
+  test_constraint<bool>();
+  test_constraint<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_constraint<wchar_t>();
+#endif
+  test_constraint<std::char16_t>();
----------------
mordante wrote:

Can you test for the following types too? `char8_t`, `float`, `double`, and `long double`.

https://github.com/llvm/llvm-project/pull/77967


More information about the libcxx-commits mailing list