1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03, c++11, c++14 10 // <optional> 11 12 // constexpr optional(nullopt_t) noexcept; 13 14 #include <optional> 15 #include <type_traits> 16 #include <cassert> 17 18 #include "archetypes.hpp" 19 20 using std::optional; 21 using std::nullopt_t; 22 using std::nullopt; 23 24 template <class Opt> 25 void 26 test_constexpr() 27 { 28 static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, ""); 29 static_assert(std::is_trivially_destructible<Opt>::value, ""); 30 static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, ""); 31 32 constexpr Opt opt(nullopt); 33 static_assert(static_cast<bool>(opt) == false, ""); 34 35 struct test_constexpr_ctor 36 : public Opt 37 { 38 constexpr test_constexpr_ctor() {} 39 }; 40 } 41 42 template <class Opt> 43 void 44 test() 45 { 46 static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, ""); 47 static_assert(!std::is_trivially_destructible<Opt>::value, ""); 48 static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, ""); 49 { 50 Opt opt(nullopt); 51 assert(static_cast<bool>(opt) == false); 52 } 53 { 54 const Opt opt(nullopt); 55 assert(static_cast<bool>(opt) == false); 56 } 57 struct test_constexpr_ctor 58 : public Opt 59 { 60 constexpr test_constexpr_ctor() {} 61 }; 62 } 63 64 int main(int, char**) 65 { 66 test_constexpr<optional<int>>(); 67 test_constexpr<optional<int*>>(); 68 test_constexpr<optional<ImplicitTypes::NoCtors>>(); 69 test_constexpr<optional<NonTrivialTypes::NoCtors>>(); 70 test_constexpr<optional<NonConstexprTypes::NoCtors>>(); 71 test<optional<NonLiteralTypes::NoCtors>>(); 72 73 return 0; 74 } 75