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 // <optional>
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: clang-5, apple-clang-9
12 // UNSUPPORTED: libcpp-no-deduction-guides
13 // Clang 5 will generate bad implicit deduction guides
14 //  Specifically, for the copy constructor.
15 
16 
17 // template<class T>
18 //   optional(T) -> optional<T>;
19 
20 
21 #include <optional>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 struct A {};
27 
main(int,char **)28 int main(int, char**)
29 {
30 //  Test the explicit deduction guides
31     {
32 //  optional(T)
33     std::optional opt(5);
34     static_assert(std::is_same_v<decltype(opt), std::optional<int>>, "");
35     assert(static_cast<bool>(opt));
36     assert(*opt == 5);
37     }
38 
39     {
40 //  optional(T)
41     std::optional opt(A{});
42     static_assert(std::is_same_v<decltype(opt), std::optional<A>>, "");
43     assert(static_cast<bool>(opt));
44     }
45 
46 //  Test the implicit deduction guides
47     {
48 //  optional(optional);
49     std::optional<char> source('A');
50     std::optional opt(source);
51     static_assert(std::is_same_v<decltype(opt), std::optional<char>>, "");
52     assert(static_cast<bool>(opt) == static_cast<bool>(source));
53     assert(*opt == *source);
54     }
55 
56   return 0;
57 }
58