Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.ctor / nullopt_t.pass.cpp
blob36a60f29da854da136b2f07f895d73e186580d32
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // <optional>
12 // constexpr optional(nullopt_t) noexcept;
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
18 #include "archetypes.h"
20 #include "test_macros.h"
22 using std::optional;
23 using std::nullopt_t;
24 using std::nullopt;
26 template <class Opt>
27 void
28 test_constexpr()
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
38 : public Opt
40 constexpr test_constexpr_ctor() {}
44 template <class Opt>
45 void
46 test()
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, "");
52 Opt opt(nullopt);
53 assert(static_cast<bool>(opt) == false);
56 const Opt opt(nullopt);
57 assert(static_cast<bool>(opt) == false);
59 struct test_constexpr_ctor
60 : public Opt
62 constexpr test_constexpr_ctor() {}
66 int main(int, char**)
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>>();
75 return 0;