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