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