• 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 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 
12 // <optional>
13 
14 // optional(const optional<T>& rhs);
15 
16 #include <optional>
17 #include <string>
18 #include <type_traits>
19 
20 using std::optional;
21 
22 struct X {};
23 
24 struct Y
25 {
26     Y() = default;
YY27     Y(const Y&) {}
28 };
29 
30 struct Z
31 {
32     Z() = default;
33     Z(Z&&) = delete;
34     Z(const Z&) = delete;
35     Z& operator=(Z&&) = delete;
36     Z& operator=(const Z&) = delete;
37 };
38 
main()39 int main()
40 {
41     {
42         using T = int;
43         static_assert((std::is_trivially_copy_constructible<optional<T>>::value), "");
44         constexpr optional<T> opt;
45         constexpr optional<T> opt2 = opt;
46         (void)opt2;
47     }
48     {
49         using T = X;
50         static_assert((std::is_trivially_copy_constructible<optional<T>>::value), "");
51         constexpr optional<T> opt;
52         constexpr optional<T> opt2 = opt;
53         (void)opt2;
54     }
55     static_assert(!(std::is_trivially_copy_constructible<optional<Y>>::value), "");
56     static_assert(!(std::is_trivially_copy_constructible<optional<std::string>>::value), "");
57 
58     static_assert(!(std::is_copy_constructible<optional<Z>>::value), "");
59 }
60