• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_lvalue_reference
13 // If T names a referenceable type then the member typedef type
14 //    shall name T&; otherwise, type shall name T.
15 
16 #include <type_traits>
17 #include "test_macros.h"
18 
19 template <class T, class U>
test_add_lvalue_reference()20 void test_add_lvalue_reference()
21 {
22     static_assert((std::is_same<typename std::add_lvalue_reference<T>::type, U>::value), "");
23 #if TEST_STD_VER > 11
24     static_assert((std::is_same<std::add_lvalue_reference_t<T>, U>::value), "");
25 #endif
26 }
27 
28 template <class F>
test_function0()29 void test_function0()
30 {
31     static_assert((std::is_same<typename std::add_lvalue_reference<F>::type, F&>::value), "");
32 #if TEST_STD_VER > 11
33     static_assert((std::is_same<std::add_lvalue_reference_t<F>, F&>::value), "");
34 #endif
35 }
36 
37 template <class F>
test_function1()38 void test_function1()
39 {
40     static_assert((std::is_same<typename std::add_lvalue_reference<F>::type, F>::value), "");
41 #if TEST_STD_VER > 11
42     static_assert((std::is_same<std::add_lvalue_reference_t<F>, F>::value), "");
43 #endif
44 }
45 
46 struct Foo {};
47 
main()48 int main()
49 {
50     test_add_lvalue_reference<void, void>();
51     test_add_lvalue_reference<int, int&>();
52     test_add_lvalue_reference<int[3], int(&)[3]>();
53     test_add_lvalue_reference<int&, int&>();
54     test_add_lvalue_reference<const int&, const int&>();
55     test_add_lvalue_reference<int*, int*&>();
56     test_add_lvalue_reference<const int*, const int*&>();
57     test_add_lvalue_reference<Foo, Foo&>();
58 
59 //  LWG 2101 specifically talks about add_lvalue_reference 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