1a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
2a9e65961SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a9e65961SEric Fiselier //
7a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
8a9e65961SEric Fiselier
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10a9e65961SEric Fiselier // <optional>
11a9e65961SEric Fiselier
12a9e65961SEric Fiselier // constexpr optional() noexcept;
13a9e65961SEric Fiselier
14a9e65961SEric Fiselier #include <optional>
15a9e65961SEric Fiselier #include <type_traits>
16a9e65961SEric Fiselier #include <cassert>
17a9e65961SEric Fiselier
18a9e65961SEric Fiselier #include "test_macros.h"
19cc89063bSNico Weber #include "archetypes.h"
20a9e65961SEric Fiselier
21a9e65961SEric Fiselier using std::optional;
22a9e65961SEric Fiselier
23a9e65961SEric Fiselier template <class Opt>
24a9e65961SEric Fiselier void
test_constexpr()25a9e65961SEric Fiselier test_constexpr()
26a9e65961SEric Fiselier {
27a9e65961SEric Fiselier static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
28a9e65961SEric Fiselier static_assert(std::is_trivially_destructible<Opt>::value, "");
29a9e65961SEric Fiselier static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");
30a9e65961SEric Fiselier
31a9e65961SEric Fiselier constexpr Opt opt;
32a9e65961SEric Fiselier static_assert(static_cast<bool>(opt) == false, "");
33a9e65961SEric Fiselier
34a9e65961SEric Fiselier struct test_constexpr_ctor
35a9e65961SEric Fiselier : public Opt
36a9e65961SEric Fiselier {
37a9e65961SEric Fiselier constexpr test_constexpr_ctor() {}
38a9e65961SEric Fiselier };
39a9e65961SEric Fiselier }
40a9e65961SEric Fiselier
41a9e65961SEric Fiselier template <class Opt>
42a9e65961SEric Fiselier void
test()43a9e65961SEric Fiselier test()
44a9e65961SEric Fiselier {
45a9e65961SEric Fiselier static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
46a9e65961SEric Fiselier static_assert(!std::is_trivially_destructible<Opt>::value, "");
47a9e65961SEric Fiselier static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");
48a9e65961SEric Fiselier {
49a9e65961SEric Fiselier Opt opt;
50a9e65961SEric Fiselier assert(static_cast<bool>(opt) == false);
51a9e65961SEric Fiselier }
52a9e65961SEric Fiselier {
53a9e65961SEric Fiselier const Opt opt;
54a9e65961SEric Fiselier assert(static_cast<bool>(opt) == false);
55a9e65961SEric Fiselier }
56a9e65961SEric Fiselier
57a9e65961SEric Fiselier struct test_constexpr_ctor
58a9e65961SEric Fiselier : public Opt
59a9e65961SEric Fiselier {
60a9e65961SEric Fiselier constexpr test_constexpr_ctor() {}
61a9e65961SEric Fiselier };
62a9e65961SEric Fiselier }
63a9e65961SEric Fiselier
main(int,char **)642df59c50SJF Bastien int main(int, char**)
65a9e65961SEric Fiselier {
66a9e65961SEric Fiselier test_constexpr<optional<int>>();
67a9e65961SEric Fiselier test_constexpr<optional<int*>>();
68a9e65961SEric Fiselier test_constexpr<optional<ImplicitTypes::NoCtors>>();
69a9e65961SEric Fiselier test_constexpr<optional<NonTrivialTypes::NoCtors>>();
70a9e65961SEric Fiselier test_constexpr<optional<NonConstexprTypes::NoCtors>>();
71a9e65961SEric Fiselier test<optional<NonLiteralTypes::NoCtors>>();
72a9e65961SEric Fiselier // EXTENSIONS
73a9e65961SEric Fiselier #if defined(_LIBCPP_VERSION) && 0 // FIXME these extensions are currently disabled.
74a9e65961SEric Fiselier test_constexpr<optional<int&>>();
75a9e65961SEric Fiselier test_constexpr<optional<const int&>>();
76a9e65961SEric Fiselier test_constexpr<optional<int&>>();
77a9e65961SEric Fiselier test_constexpr<optional<NonLiteralTypes::NoCtors&>>();
78a9e65961SEric Fiselier test_constexpr<optional<NonLiteralTypes::NoCtors&&>>();
79a9e65961SEric Fiselier #endif
802df59c50SJF Bastien
812df59c50SJF Bastien return 0;
82a9e65961SEric Fiselier }
83