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 // type_traits
10
11 // add_pointer
12 // If T names a referenceable type or a (possibly cv-qualified) void type then
13 // the member typedef type shall name the same type as remove_reference_t<T>*;
14 // otherwise, type shall name T.
15
16 #include <type_traits>
17 #include "test_macros.h"
18
19 template <class T, class U>
test_add_pointer()20 void test_add_pointer()
21 {
22 ASSERT_SAME_TYPE(U, typename std::add_pointer<T>::type);
23 #if TEST_STD_VER > 11
24 ASSERT_SAME_TYPE(U, std::add_pointer_t<T>);
25 #endif
26 }
27
28 template <class F>
test_function0()29 void test_function0()
30 {
31 ASSERT_SAME_TYPE(F*, typename std::add_pointer<F>::type);
32 #if TEST_STD_VER > 11
33 ASSERT_SAME_TYPE(F*, std::add_pointer_t<F>);
34 #endif
35 }
36
37 template <class F>
test_function1()38 void test_function1()
39 {
40 ASSERT_SAME_TYPE(F, typename std::add_pointer<F>::type);
41 #if TEST_STD_VER > 11
42 ASSERT_SAME_TYPE(F, std::add_pointer_t<F>);
43 #endif
44 }
45
46 struct Foo {};
47
main(int,char **)48 int main(int, char**)
49 {
50 test_add_pointer<void, void*>();
51 test_add_pointer<int, int*>();
52 test_add_pointer<int[3], int(*)[3]>();
53 test_add_pointer<int&, int*>();
54 test_add_pointer<const int&, const int*>();
55 test_add_pointer<int*, int**>();
56 test_add_pointer<const int*, const int**>();
57 test_add_pointer<Foo, Foo*>();
58
59 // LWG 2101 specifically talks about add_pointer and functions.
60 // The term of art is "a referenceable type", which a cv- or ref-qualified function is not.
61 test_function0<void()>();
62 #if TEST_STD_VER >= 11
63 test_function1<void() const>();
64 test_function1<void() &>();
65 test_function1<void() &&>();
66 test_function1<void() const &>();
67 test_function1<void() const &&>();
68 #endif
69
70 // But a cv- or ref-qualified member function *is* "a referenceable type"
71 test_function0<void (Foo::*)()>();
72 #if TEST_STD_VER >= 11
73 test_function0<void (Foo::*)() const>();
74 test_function0<void (Foo::*)() &>();
75 test_function0<void (Foo::*)() &&>();
76 test_function0<void (Foo::*)() const &>();
77 test_function0<void (Foo::*)() const &&>();
78 #endif
79
80 return 0;
81 }
82