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_nothrow_assignable
12
13 #include <type_traits>
14 #include "test_macros.h"
15
16 template <class T, class U>
test_is_nothrow_assignable()17 void test_is_nothrow_assignable()
18 {
19 static_assert(( std::is_nothrow_assignable<T, U>::value), "");
20 #if TEST_STD_VER > 14
21 static_assert(( std::is_nothrow_assignable_v<T, U>), "");
22 #endif
23 }
24
25 template <class T, class U>
test_is_not_nothrow_assignable()26 void test_is_not_nothrow_assignable()
27 {
28 static_assert((!std::is_nothrow_assignable<T, U>::value), "");
29 #if TEST_STD_VER > 14
30 static_assert((!std::is_nothrow_assignable_v<T, U>), "");
31 #endif
32 }
33
34 struct A
35 {
36 };
37
38 struct B
39 {
40 void operator=(A);
41 };
42
43 struct C
44 {
45 void operator=(C&); // not const
46 };
47
main(int,char **)48 int main(int, char**)
49 {
50 test_is_nothrow_assignable<int&, int&> ();
51 test_is_nothrow_assignable<int&, int> ();
52 #if TEST_STD_VER >= 11
53 test_is_nothrow_assignable<int&, double> ();
54 #endif
55
56 test_is_not_nothrow_assignable<int, int&> ();
57 test_is_not_nothrow_assignable<int, int> ();
58 test_is_not_nothrow_assignable<B, A> ();
59 test_is_not_nothrow_assignable<A, B> ();
60 test_is_not_nothrow_assignable<C, C&> ();
61
62 return 0;
63 }
64