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() noexcept;
15 #include <type_traits>
18 #include "test_macros.h"
19 #include "archetypes.h"
27 static_assert(std::is_nothrow_default_constructible
<Opt
>::value
, "");
28 static_assert(std::is_trivially_destructible
<Opt
>::value
, "");
29 static_assert(std::is_trivially_destructible
<typename
Opt::value_type
>::value
, "");
32 static_assert(static_cast<bool>(opt
) == false, "");
34 struct test_constexpr_ctor
37 constexpr test_constexpr_ctor() {}
45 static_assert(std::is_nothrow_default_constructible
<Opt
>::value
, "");
46 static_assert(!std::is_trivially_destructible
<Opt
>::value
, "");
47 static_assert(!std::is_trivially_destructible
<typename
Opt::value_type
>::value
, "");
50 assert(static_cast<bool>(opt
) == false);
54 assert(static_cast<bool>(opt
) == false);
57 struct test_constexpr_ctor
60 constexpr test_constexpr_ctor() {}
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
>>();
73 #if defined(_LIBCPP_VERSION) && 0 // FIXME these extensions are currently disabled.
74 test_constexpr
<optional
<int&>>();
75 test_constexpr
<optional
<const int&>>();
76 test_constexpr
<optional
<int&>>();
77 test_constexpr
<optional
<NonLiteralTypes::NoCtors
&>>();
78 test_constexpr
<optional
<NonLiteralTypes::NoCtors
&&>>();