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 // is_assignable
12
13 #include <type_traits>
14 #include "test_macros.h"
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 #if TEST_STD_VER > 14
30 static_assert( std::is_assignable_v<T, U>, "");
31 #endif
32 }
33
34 template <class T, class U>
test_is_not_assignable()35 void test_is_not_assignable()
36 {
37 static_assert((!std::is_assignable<T, U>::value), "");
38 #if TEST_STD_VER > 14
39 static_assert( !std::is_assignable_v<T, U>, "");
40 #endif
41 }
42
43 struct D;
44
45 #if TEST_STD_VER >= 11
46 struct C
47 {
48 template <class U>
49 D operator,(U&&);
50 };
51
52 struct E
53 {
54 C operator=(int);
55 };
56 #endif
57
58 template <typename T>
59 struct X { T t; };
60
main(int,char **)61 int main(int, char**)
62 {
63 test_is_assignable<int&, int&> ();
64 test_is_assignable<int&, int> ();
65 test_is_assignable<int&, double> ();
66 test_is_assignable<B, A> ();
67 test_is_assignable<void*&, void*> ();
68
69 #if TEST_STD_VER >= 11
70 test_is_assignable<E, int> ();
71
72 test_is_not_assignable<int, int&> ();
73 test_is_not_assignable<int, int> ();
74 #endif
75 test_is_not_assignable<A, B> ();
76 test_is_not_assignable<void, const void> ();
77 test_is_not_assignable<const void, const void> ();
78 test_is_not_assignable<int(), int> ();
79
80 // pointer to incomplete template type
81 test_is_assignable<X<D>*&, X<D>*> ();
82
83 return 0;
84 }
85