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// <optional>
11
12// constexpr optional() noexcept;
13
14#include <experimental/optional>
15#include <type_traits>
16#include <cassert>
17
18#if _LIBCPP_STD_VER > 11
19
20using std::experimental::optional;
21
22template <class Opt>
23void
24test_constexpr()
25{
26    static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
27    constexpr Opt opt;
28    static_assert(static_cast<bool>(opt) == false, "");
29
30    struct test_constexpr_ctor
31        : public Opt
32    {
33        constexpr test_constexpr_ctor() {}
34    };
35
36}
37
38template <class Opt>
39void
40test()
41{
42    static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
43    Opt opt;
44    assert(static_cast<bool>(opt) == false);
45
46    struct test_constexpr_ctor
47        : public Opt
48    {
49        constexpr test_constexpr_ctor() {}
50    };
51}
52
53struct X
54{
55    X();
56};
57
58#endif  // _LIBCPP_STD_VER > 11
59
60int main()
61{
62#if _LIBCPP_STD_VER > 11
63    test_constexpr<optional<int>>();
64    test_constexpr<optional<int*>>();
65    test<optional<X>>();
66#endif  // _LIBCPP_STD_VER > 11
67}
68