[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / numerics / numeric.ops / numeric.ops.midpoint / midpoint.pointer.pass.cpp
blob5138fd6a37469f7d8ef06c96a7f2d5c42589a656
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // <numeric>
12 // template <class _Tp>
13 // _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept
16 #include <numeric>
17 #include <cassert>
19 #include "test_macros.h"
23 template <typename T>
24 constexpr void constexpr_test()
26 constexpr T array[1000] = {};
27 ASSERT_SAME_TYPE(decltype(std::midpoint(array, array)), const T*);
28 ASSERT_NOEXCEPT( std::midpoint(array, array));
30 static_assert(std::midpoint(array, array) == array, "");
31 static_assert(std::midpoint(array, array + 1000) == array + 500, "");
33 static_assert(std::midpoint(array, array + 9) == array + 4, "");
34 static_assert(std::midpoint(array, array + 10) == array + 5, "");
35 static_assert(std::midpoint(array, array + 11) == array + 5, "");
36 static_assert(std::midpoint(array + 9, array) == array + 5, "");
37 static_assert(std::midpoint(array + 10, array) == array + 5, "");
38 static_assert(std::midpoint(array + 11, array) == array + 6, "");
41 template <typename T>
42 void runtime_test()
44 T array[1000] = {}; // we need an array to make valid pointers
45 ASSERT_SAME_TYPE(decltype(std::midpoint(array, array)), T*);
46 ASSERT_NOEXCEPT( std::midpoint(array, array));
48 assert(std::midpoint(array, array) == array);
49 assert(std::midpoint(array, array + 1000) == array + 500);
51 assert(std::midpoint(array, array + 9) == array + 4);
52 assert(std::midpoint(array, array + 10) == array + 5);
53 assert(std::midpoint(array, array + 11) == array + 5);
54 assert(std::midpoint(array + 9, array) == array + 5);
55 assert(std::midpoint(array + 10, array) == array + 5);
56 assert(std::midpoint(array + 11, array) == array + 6);
58 // explicit instantiation
59 ASSERT_SAME_TYPE(decltype(std::midpoint<T>(array, array)), T*);
60 ASSERT_NOEXCEPT(std::midpoint<T>(array, array));
61 assert(std::midpoint<T>(array, array) == array);
62 assert(std::midpoint<T>(array, array + 1000) == array + 500);
65 template <typename T>
66 void pointer_test()
68 runtime_test< T>();
69 runtime_test<const T>();
70 runtime_test< volatile T>();
71 runtime_test<const volatile T>();
73 // The constexpr tests are always const, but we can test them anyway.
74 constexpr_test< T>();
75 constexpr_test<const T>();
77 // GCC 9.0.1 (unreleased as of 2019-03) barfs on this, but we have a bot for it.
78 // Uncomment when gcc 9.1 is released
79 #ifndef TEST_COMPILER_GCC
80 constexpr_test< volatile T>();
81 constexpr_test<const volatile T>();
82 #endif
86 int main(int, char**)
88 pointer_test<char>();
89 pointer_test<int>();
90 pointer_test<double>();
92 return 0;