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// XFAIL: with_system_cxx_lib=macosx10.12
13// XFAIL: with_system_cxx_lib=macosx10.11
14// XFAIL: with_system_cxx_lib=macosx10.10
15// XFAIL: with_system_cxx_lib=macosx10.9
16// XFAIL: with_system_cxx_lib=macosx10.7
17// XFAIL: with_system_cxx_lib=macosx10.8
18
19// <optional>
20
21// constexpr const T& optional<T>::value() const &;
22
23#include <optional>
24#include <type_traits>
25#include <cassert>
26
27#include "test_macros.h"
28
29using std::optional;
30using std::in_place_t;
31using std::in_place;
32using std::bad_optional_access;
33
34struct X
35{
36    X() = default;
37    X(const X&) = delete;
38    constexpr int test() const & {return 3;}
39    int test() & {return 4;}
40    constexpr int test() const && {return 5;}
41    int test() && {return 6;}
42};
43
44int main()
45{
46    {
47        const optional<X> opt; ((void)opt);
48        ASSERT_NOT_NOEXCEPT(opt.value());
49        ASSERT_SAME_TYPE(decltype(opt.value()), X const&);
50    }
51    {
52        constexpr optional<X> opt(in_place);
53        static_assert(opt.value().test() == 3, "");
54    }
55    {
56        const optional<X> opt(in_place);
57        assert(opt.value().test() == 3);
58    }
59#ifndef TEST_HAS_NO_EXCEPTIONS
60    {
61        const optional<X> opt;
62        try
63        {
64            (void)opt.value();
65            assert(false);
66        }
67        catch (const bad_optional_access&)
68        {
69        }
70    }
71#endif
72}
73