[SandboxVec][Utils] Implement Utils::verifyFunction() (#124356)
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.ctor / default.pass.cpp
blob61a365edb64eaf1b7f4cc875ace727093f17ed83
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() noexcept;
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "archetypes.h"
21 using std::optional;
23 template <class Opt>
24 void
25 test_constexpr()
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, "");
31 constexpr Opt opt;
32 static_assert(static_cast<bool>(opt) == false, "");
34 struct test_constexpr_ctor
35 : public Opt
37 constexpr test_constexpr_ctor() {}
41 template <class Opt>
42 void
43 test()
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, "");
49 Opt opt;
50 assert(static_cast<bool>(opt) == false);
53 const Opt opt;
54 assert(static_cast<bool>(opt) == false);
57 struct test_constexpr_ctor
58 : public Opt
60 constexpr test_constexpr_ctor() {}
64 int main(int, char**)
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 // EXTENSIONS
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&&>>();
79 #endif
81 return 0;