1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
12 // constexpr optional(nullopt_t) noexcept;
15 #include <type_traits>
18 #include "archetypes.h"
20 #include "test_macros.h"
30 static_assert(std::is_nothrow_constructible
<Opt
, nullopt_t
&>::value
, "");
31 static_assert(std::is_trivially_destructible
<Opt
>::value
, "");
32 static_assert(std::is_trivially_destructible
<typename
Opt::value_type
>::value
, "");
34 constexpr Opt
opt(nullopt
);
35 static_assert(static_cast<bool>(opt
) == false, "");
37 struct test_constexpr_ctor
40 constexpr test_constexpr_ctor() {}
48 static_assert(std::is_nothrow_constructible
<Opt
, nullopt_t
&>::value
, "");
49 static_assert(!std::is_trivially_destructible
<Opt
>::value
, "");
50 static_assert(!std::is_trivially_destructible
<typename
Opt::value_type
>::value
, "");
53 assert(static_cast<bool>(opt
) == false);
56 const Opt
opt(nullopt
);
57 assert(static_cast<bool>(opt
) == false);
59 struct test_constexpr_ctor
62 constexpr test_constexpr_ctor() {}
68 test_constexpr
<optional
<int>>();
69 test_constexpr
<optional
<int*>>();
70 test_constexpr
<optional
<ImplicitTypes::NoCtors
>>();
71 test_constexpr
<optional
<NonTrivialTypes::NoCtors
>>();
72 test_constexpr
<optional
<NonConstexprTypes::NoCtors
>>();
73 test
<optional
<NonLiteralTypes::NoCtors
>>();