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 // <memory>
10
11 // template <class T>
12 // struct pointer_traits<T*>
13 // {
14 // static pointer pointer_to(<details>); // constexpr in C++20
15 // ...
16 // };
17
18 #include <memory>
19 #include <cassert>
20
21 #include "test_macros.h"
22
test()23 TEST_CONSTEXPR_CXX20 bool test()
24 {
25 {
26 int i = 0;
27 static_assert(std::is_same<decltype(std::pointer_traits<int*>::pointer_to(i)), int*>::value, "");
28 assert(std::pointer_traits<int*>::pointer_to(i) == &i);
29 }
30 {
31 int i = 0;
32 static_assert(std::is_same<decltype(std::pointer_traits<const int*>::pointer_to(i)), const int*>::value, "");
33 assert(std::pointer_traits<const int*>::pointer_to(i) == &i);
34 }
35 return true;
36 }
37
main(int,char **)38 int main(int, char**)
39 {
40 test();
41 #if TEST_STD_VER > 17
42 static_assert(test());
43 #endif
44
45 {
46 // Check that pointer_traits<void*> is still well-formed, even though it has no pointer_to.
47 static_assert(std::is_same<std::pointer_traits<void*>::element_type, void>::value, "");
48 static_assert(std::is_same<std::pointer_traits<const void*>::element_type, const void>::value, "");
49 static_assert(std::is_same<std::pointer_traits<volatile void*>::element_type, volatile void>::value, "");
50 }
51
52 return 0;
53 }
54