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 // is_assignable
13
14 #include <type_traits>
15
16 struct A
17 {
18 };
19
20 struct B
21 {
22 void operator=(A);
23 };
24
25 template <class T, class U>
test_is_assignable()26 void test_is_assignable()
27 {
28 static_assert(( std::is_assignable<T, U>::value), "");
29 }
30
31 template <class T, class U>
test_is_not_assignable()32 void test_is_not_assignable()
33 {
34 static_assert((!std::is_assignable<T, U>::value), "");
35 }
36
37 struct D;
38
39 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
40 struct C
41 {
42 template <class U>
43 D operator,(U&&);
44 };
45
46 struct E
47 {
48 C operator=(int);
49 };
50 #endif
51
52 template <typename T>
53 struct X { T t; };
54
main()55 int main()
56 {
57 test_is_assignable<int&, int&> ();
58 test_is_assignable<int&, int> ();
59 test_is_assignable<int&, double> ();
60 test_is_assignable<B, A> ();
61 test_is_assignable<void*&, void*> ();
62
63 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
64 test_is_assignable<E, int> ();
65
66 test_is_not_assignable<int, int&> ();
67 test_is_not_assignable<int, int> ();
68 #endif
69 test_is_not_assignable<A, B> ();
70 test_is_not_assignable<void, const void> ();
71 test_is_not_assignable<const void, const void> ();
72 test_is_not_assignable<int(), int> ();
73
74 // pointer to incomplete template type
75 test_is_assignable<X<D>*&, X<D>*> ();
76 }
77