Home | History | Annotate | Download | only in optional.object.ctor
      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 
     20 using std::experimental::optional;
     21 
     22 template <class Opt>
     23 void
     24 test_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 
     38 template <class Opt>
     39 void
     40 test()
     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 
     53 struct X
     54 {
     55     X();
     56 };
     57 
     58 #endif  // _LIBCPP_STD_VER > 11
     59 
     60 int 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