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 //===----------------------------------------------------------------------===//
12 // struct pointer_traits<T*>
14 // static pointer pointer_to(<details>) noexcept; // constexpr in C++20
20 #include <type_traits>
22 #include "test_macros.h"
24 TEST_CONSTEXPR_CXX20
bool test()
29 static_assert(std::is_same
<decltype(std::pointer_traits
<int*>::pointer_to(i
)), int*>::value
, "");
30 ASSERT_NOEXCEPT(std::pointer_traits
<int*>::pointer_to(i
));
31 assert(std::pointer_traits
<int*>::pointer_to(i
) == &i
);
33 // pointer_traits<const T*>
36 static_assert(std::is_same
<decltype(std::pointer_traits
<const int*>::pointer_to(i
)), const int*>::value
, "");
37 ASSERT_NOEXCEPT(std::pointer_traits
<const int*>::pointer_to(i
));
38 assert(std::pointer_traits
<const int*>::pointer_to(i
) == &i
);
40 // pointer_traits<const T*> with a non-const argument
43 static_assert(std::is_same
<decltype(std::pointer_traits
<const int*>::pointer_to(i
)), const int*>::value
, "");
44 ASSERT_NOEXCEPT(std::pointer_traits
<const int*>::pointer_to(i
));
45 assert(std::pointer_traits
<const int*>::pointer_to(i
) == &i
);
54 static_assert(test());
58 // Check that pointer_traits<void*> is still well-formed, even though it has no pointer_to.
59 static_assert(std::is_same
<std::pointer_traits
<void*>::element_type
, void>::value
, "");
60 static_assert(std::is_same
<std::pointer_traits
<const void*>::element_type
, const void>::value
, "");
61 static_assert(std::is_same
<std::pointer_traits
<volatile void*>::element_type
, volatile void>::value
, "");