• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <optional>
12 
13 // constexpr optional(nullopt_t) noexcept;
14 
15 #include <optional>
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "archetypes.hpp"
20 
21 using std::optional;
22 using std::nullopt_t;
23 using std::nullopt;
24 
25 template <class Opt>
26 void
test_constexpr()27 test_constexpr()
28 {
29     static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
30     static_assert(std::is_trivially_destructible<Opt>::value, "");
31     static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");
32 
33     constexpr Opt opt(nullopt);
34     static_assert(static_cast<bool>(opt) == false, "");
35 
36     struct test_constexpr_ctor
37         : public Opt
38     {
39         constexpr test_constexpr_ctor() {}
40     };
41 }
42 
43 template <class Opt>
44 void
test()45 test()
46 {
47     static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
48     static_assert(!std::is_trivially_destructible<Opt>::value, "");
49     static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");
50     {
51     Opt opt(nullopt);
52     assert(static_cast<bool>(opt) == false);
53     }
54     {
55     const Opt opt(nullopt);
56     assert(static_cast<bool>(opt) == false);
57     }
58     struct test_constexpr_ctor
59         : public Opt
60     {
61         constexpr test_constexpr_ctor() {}
62     };
63 }
64 
main()65 int main()
66 {
67     test_constexpr<optional<int>>();
68     test_constexpr<optional<int*>>();
69     test_constexpr<optional<ImplicitTypes::NoCtors>>();
70     test_constexpr<optional<NonTrivialTypes::NoCtors>>();
71     test_constexpr<optional<NonConstexprTypes::NoCtors>>();
72     test<optional<NonLiteralTypes::NoCtors>>();
73 }
74