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 // UNSUPPORTED: c++03, c++11, c++14
10
11 // <optional>
12
13 // optional<T>& operator=(const optional<T>& rhs);
14
15 #include <optional>
16 #include <string>
17 #include <type_traits>
18
19 #include "test_macros.h"
20
21 using std::optional;
22
23 struct X {};
24
25 struct Y
26 {
27 Y() = default;
operator =Y28 Y& operator=(const Y&) { return *this; }
29 };
30
31 struct Z1
32 {
33 Z1() = default;
34 Z1(Z1&&) = default;
35 Z1(const Z1&) = default;
36 Z1& operator=(Z1&&) = default;
37 Z1& operator=(const Z1&) = delete;
38 };
39
40 struct Z2
41 {
42 Z2() = default;
43 Z2(Z2&&) = default;
44 Z2(const Z2&) = delete;
45 Z2& operator=(Z2&&) = default;
46 Z2& operator=(const Z2&) = default;
47 };
48
49 template <class T>
50 constexpr bool
test()51 test()
52 {
53 optional<T> opt;
54 optional<T> opt2;
55 opt = opt2;
56 return true;
57 }
58
main(int,char **)59 int main(int, char**)
60 {
61 {
62 using T = int;
63 static_assert((std::is_trivially_copy_assignable<optional<T>>::value), "");
64 static_assert(test<T>(), "");
65 }
66 {
67 using T = X;
68 static_assert((std::is_trivially_copy_assignable<optional<T>>::value), "");
69 static_assert(test<T>(), "");
70 }
71 static_assert(!(std::is_trivially_copy_assignable<optional<Y>>::value), "");
72 static_assert(!(std::is_trivially_copy_assignable<optional<std::string>>::value), "");
73
74 static_assert(!(std::is_copy_assignable<optional<Z1>>::value), "");
75 static_assert(!(std::is_copy_assignable<optional<Z2>>::value), "");
76
77 return 0;
78 }
79