1a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
2a9e65961SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a9e65961SEric Fiselier //
7a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
8a9e65961SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
102659663eSLouis Dionne 
112659663eSLouis Dionne // Throwing bad_optional_access is supported starting in macosx10.13
12c360553cSLouis Dionne // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} && !no-exceptions
1351358e45SLouis Dionne 
14a9e65961SEric Fiselier // <optional>
1551358e45SLouis Dionne //
16a9e65961SEric Fiselier // template <class T>
17a9e65961SEric Fiselier //   constexpr optional<decay_t<T>> make_optional(T&& v);
18a9e65961SEric Fiselier 
19a9e65961SEric Fiselier #include <optional>
20a9e65961SEric Fiselier #include <string>
21a9e65961SEric Fiselier #include <memory>
22a9e65961SEric Fiselier #include <cassert>
23a9e65961SEric Fiselier 
24a9e65961SEric Fiselier #include "test_macros.h"
25a9e65961SEric Fiselier 
main(int,char **)262df59c50SJF Bastien int main(int, char**)
27a9e65961SEric Fiselier {
28a9e65961SEric Fiselier     {
29*2b2ee24dSArthur O'Dwyer         int arr[10];
30*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional(arr);
31*2b2ee24dSArthur O'Dwyer         ASSERT_SAME_TYPE(decltype(opt), std::optional<int*>);
32*2b2ee24dSArthur O'Dwyer         assert(*opt == arr);
33a9e65961SEric Fiselier     }
34a9e65961SEric Fiselier     {
35*2b2ee24dSArthur O'Dwyer         constexpr auto opt = std::make_optional(2);
36*2b2ee24dSArthur O'Dwyer         ASSERT_SAME_TYPE(decltype(opt), const std::optional<int>);
37a9e65961SEric Fiselier         static_assert(opt.value() == 2);
38a9e65961SEric Fiselier     }
39a9e65961SEric Fiselier     {
40*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional(2);
41*2b2ee24dSArthur O'Dwyer         ASSERT_SAME_TYPE(decltype(opt), std::optional<int>);
42a9e65961SEric Fiselier         assert(*opt == 2);
43a9e65961SEric Fiselier     }
44a9e65961SEric Fiselier     {
45*2b2ee24dSArthur O'Dwyer         const std::string s = "123";
46*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional(s);
47*2b2ee24dSArthur O'Dwyer         ASSERT_SAME_TYPE(decltype(opt), std::optional<std::string>);
48*2b2ee24dSArthur O'Dwyer         assert(*opt == "123");
49a9e65961SEric Fiselier     }
50a9e65961SEric Fiselier     {
51*2b2ee24dSArthur O'Dwyer         std::unique_ptr<int> s = std::make_unique<int>(3);
52*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional(std::move(s));
53*2b2ee24dSArthur O'Dwyer         ASSERT_SAME_TYPE(decltype(opt), std::optional<std::unique_ptr<int>>);
54a9e65961SEric Fiselier         assert(**opt == 3);
55a9e65961SEric Fiselier         assert(s == nullptr);
56a9e65961SEric Fiselier     }
572df59c50SJF Bastien 
582df59c50SJF Bastien   return 0;
59a9e65961SEric Fiselier }
60