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