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++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.h"
19
20#include "test_macros.h"
21
22using std::optional;
23using std::nullopt_t;
24using std::nullopt;
25
26template <class Opt>
27void
28test_constexpr()
29{
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, "");
33
34 constexpr Opt opt(nullopt);
35 static_assert(static_cast<bool>(opt) == false, "");
36
37 struct test_constexpr_ctor
38 : public Opt
39 {
40 constexpr test_constexpr_ctor() {}
41 };
42}
43
44template <class Opt>
45void
46test()
47{
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, "");
51 {
52 Opt opt(nullopt);
53 assert(static_cast<bool>(opt) == false);
54 }
55 {
56 const Opt opt(nullopt);
57 assert(static_cast<bool>(opt) == false);
58 }
59 struct test_constexpr_ctor
60 : public Opt
61 {
62 constexpr test_constexpr_ctor() {}
63 };
64}
65
66int main(int, char**)
67{
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>>();
74
75 return 0;
76}
77

source code of libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/nullopt_t.pass.cpp