xref: /llvm-project/libcxx/test/std/utilities/optional/optional.nullopt/nullopt_t.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
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 // struct nullopt_t{see below};
13e38efe12SCasey Carter // inline constexpr nullopt_t nullopt(unspecified);
14a9e65961SEric Fiselier 
1577dd30b5SMarshall Clow // [optional.nullopt]/2:
16e38efe12SCasey Carter //   Type nullopt_t shall not have a default constructor or an initializer-list
17e38efe12SCasey Carter //   constructor, and shall not be an aggregate.
1877dd30b5SMarshall Clow 
19a9e65961SEric Fiselier #include <optional>
20a9e65961SEric Fiselier #include <type_traits>
21a9e65961SEric Fiselier 
227fc6a556SMarshall Clow #include "test_macros.h"
237fc6a556SMarshall Clow 
24a9e65961SEric Fiselier using std::nullopt_t;
25a9e65961SEric Fiselier using std::nullopt;
26a9e65961SEric Fiselier 
test()27e38efe12SCasey Carter constexpr bool test()
28a9e65961SEric Fiselier {
29e38efe12SCasey Carter     nullopt_t foo{nullopt};
30e38efe12SCasey Carter     (void)foo;
31e38efe12SCasey Carter     return true;
32a9e65961SEric Fiselier }
33a9e65961SEric Fiselier 
main(int,char **)342df59c50SJF Bastien int main(int, char**)
35a9e65961SEric Fiselier {
36e38efe12SCasey Carter     static_assert(std::is_empty_v<nullopt_t>);
37e38efe12SCasey Carter     static_assert(!std::is_default_constructible_v<nullopt_t>);
38a9e65961SEric Fiselier 
39e38efe12SCasey Carter     static_assert(std::is_same_v<const nullopt_t, decltype(nullopt)>);
40e38efe12SCasey Carter     static_assert(test());
412df59c50SJF Bastien 
422df59c50SJF Bastien   return 0;
43a9e65961SEric Fiselier }
44