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 
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10a9e65961SEric Fiselier // <optional>
11a9e65961SEric Fiselier 
12a9e65961SEric Fiselier // constexpr optional(nullopt_t) noexcept;
13a9e65961SEric Fiselier 
14a9e65961SEric Fiselier #include <optional>
15a9e65961SEric Fiselier #include <type_traits>
16a9e65961SEric Fiselier #include <cassert>
17a9e65961SEric Fiselier 
18cc89063bSNico Weber #include "archetypes.h"
19a9e65961SEric Fiselier 
207fc6a556SMarshall Clow #include "test_macros.h"
217fc6a556SMarshall Clow 
22a9e65961SEric Fiselier using std::optional;
23a9e65961SEric Fiselier using std::nullopt_t;
24a9e65961SEric Fiselier using std::nullopt;
25a9e65961SEric Fiselier 
26a9e65961SEric Fiselier template <class Opt>
27a9e65961SEric Fiselier void
test_constexpr()28a9e65961SEric Fiselier test_constexpr()
29a9e65961SEric Fiselier {
30a9e65961SEric Fiselier     static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
31a9e65961SEric Fiselier     static_assert(std::is_trivially_destructible<Opt>::value, "");
32a9e65961SEric Fiselier     static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");
33a9e65961SEric Fiselier 
34a9e65961SEric Fiselier     constexpr Opt opt(nullopt);
35a9e65961SEric Fiselier     static_assert(static_cast<bool>(opt) == false, "");
36a9e65961SEric Fiselier 
37a9e65961SEric Fiselier     struct test_constexpr_ctor
38a9e65961SEric Fiselier         : public Opt
39a9e65961SEric Fiselier     {
40a9e65961SEric Fiselier         constexpr test_constexpr_ctor() {}
41a9e65961SEric Fiselier     };
42a9e65961SEric Fiselier }
43a9e65961SEric Fiselier 
44a9e65961SEric Fiselier template <class Opt>
45a9e65961SEric Fiselier void
test()46a9e65961SEric Fiselier test()
47a9e65961SEric Fiselier {
48a9e65961SEric Fiselier     static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
49a9e65961SEric Fiselier     static_assert(!std::is_trivially_destructible<Opt>::value, "");
50a9e65961SEric Fiselier     static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");
51a9e65961SEric Fiselier     {
52a9e65961SEric Fiselier     Opt opt(nullopt);
53a9e65961SEric Fiselier     assert(static_cast<bool>(opt) == false);
54a9e65961SEric Fiselier     }
55a9e65961SEric Fiselier     {
56a9e65961SEric Fiselier     const Opt opt(nullopt);
57a9e65961SEric Fiselier     assert(static_cast<bool>(opt) == false);
58a9e65961SEric Fiselier     }
59a9e65961SEric Fiselier     struct test_constexpr_ctor
60a9e65961SEric Fiselier         : public Opt
61a9e65961SEric Fiselier     {
62a9e65961SEric Fiselier         constexpr test_constexpr_ctor() {}
63a9e65961SEric Fiselier     };
64a9e65961SEric Fiselier }
65a9e65961SEric Fiselier 
main(int,char **)662df59c50SJF Bastien int main(int, char**)
67a9e65961SEric Fiselier {
68a9e65961SEric Fiselier     test_constexpr<optional<int>>();
69a9e65961SEric Fiselier     test_constexpr<optional<int*>>();
70a9e65961SEric Fiselier     test_constexpr<optional<ImplicitTypes::NoCtors>>();
71a9e65961SEric Fiselier     test_constexpr<optional<NonTrivialTypes::NoCtors>>();
72a9e65961SEric Fiselier     test_constexpr<optional<NonConstexprTypes::NoCtors>>();
73a9e65961SEric Fiselier     test<optional<NonLiteralTypes::NoCtors>>();
742df59c50SJF Bastien 
752df59c50SJF Bastien   return 0;
76a9e65961SEric Fiselier }
77