1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
17 // template <class _Tp>
18 // _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept
24 #include "test_macros.h"
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, "");
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);
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.
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
>();
95 pointer_test
<double>();