[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / numerics / numeric.ops / numeric.ops.midpoint / midpoint.pointer.pass.cpp
blobe8a25c174076a624b618de1842360e3c06a6a3ad
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
11 // MSVC warning C5215: a function parameter with a volatile qualified type is deprecated in C++20
12 // MSVC warning C5216: a volatile qualified return type is deprecated in C++20
13 // ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd5215 /wd5216
15 // <numeric>
17 // template <class _Tp>
18 // _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept
21 #include <numeric>
22 #include <cassert>
24 #include "test_macros.h"
28 template <typename T>
29 constexpr void constexpr_test()
31 constexpr T array[1000] = {};
32 ASSERT_SAME_TYPE(decltype(std::midpoint(array, array)), const T*);
33 ASSERT_NOEXCEPT( std::midpoint(array, array));
35 static_assert(std::midpoint(array, array) == array, "");
36 static_assert(std::midpoint(array, array + 1000) == array + 500, "");
38 static_assert(std::midpoint(array, array + 9) == array + 4, "");
39 static_assert(std::midpoint(array, array + 10) == array + 5, "");
40 static_assert(std::midpoint(array, array + 11) == array + 5, "");
41 static_assert(std::midpoint(array + 9, array) == array + 5, "");
42 static_assert(std::midpoint(array + 10, array) == array + 5, "");
43 static_assert(std::midpoint(array + 11, array) == array + 6, "");
46 template <typename T>
47 void runtime_test()
49 T array[1000] = {}; // we need an array to make valid pointers
50 ASSERT_SAME_TYPE(decltype(std::midpoint(array, array)), T*);
51 ASSERT_NOEXCEPT( std::midpoint(array, array));
53 assert(std::midpoint(array, array) == array);
54 assert(std::midpoint(array, array + 1000) == array + 500);
56 assert(std::midpoint(array, array + 9) == array + 4);
57 assert(std::midpoint(array, array + 10) == array + 5);
58 assert(std::midpoint(array, array + 11) == array + 5);
59 assert(std::midpoint(array + 9, array) == array + 5);
60 assert(std::midpoint(array + 10, array) == array + 5);
61 assert(std::midpoint(array + 11, array) == array + 6);
63 // explicit instantiation
64 ASSERT_SAME_TYPE(decltype(std::midpoint<T>(array, array)), T*);
65 ASSERT_NOEXCEPT(std::midpoint<T>(array, array));
66 assert(std::midpoint<T>(array, array) == array);
67 assert(std::midpoint<T>(array, array + 1000) == array + 500);
70 template <typename T>
71 void pointer_test()
73 runtime_test< T>();
74 runtime_test<const T>();
75 runtime_test< volatile T>();
76 runtime_test<const volatile T>();
78 // The constexpr tests are always const, but we can test them anyway.
79 constexpr_test< T>();
80 constexpr_test<const T>();
82 // GCC 9.0.1 (unreleased as of 2019-03) barfs on this, but we have a bot for it.
83 // Uncomment when gcc 9.1 is released
84 #ifndef TEST_COMPILER_GCC
85 constexpr_test< volatile T>();
86 constexpr_test<const volatile T>();
87 #endif
91 int main(int, char**)
93 pointer_test<char>();
94 pointer_test<int>();
95 pointer_test<double>();
97 return 0;