xref: /llvm-project/libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp (revision 2e43a304f10fd801f068d0f9831f01f2c5b0b2e2)
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, c++17
10 // UNSUPPORTED: no-filesystem, no-localization, no-tzdb
11 
12 // XFAIL: libcpp-has-no-experimental-tzdb
13 // XFAIL: availability-tzdb-missing
14 
15 // <chrono>
16 
17 // class leap_second
18 // {
19 //   leap_second(const leap_second&)            = default;
20 //
21 //   ...
22 // };
23 
24 #include <cassert>
25 #include <chrono>
26 #include <concepts>
27 #include <type_traits>
28 
29 #include "test_chrono_leap_second.h"
30 
31 constexpr bool test() {
32   std::chrono::leap_second a =
33       test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1});
34 
35   {
36     std::chrono::leap_second b = a;
37 
38     //  operator== only compares the date member.
39     assert(a.date() == b.date());
40     assert(a.value() == b.value());
41   }
42 
43 #ifdef _LIBCPP_VERSION
44   {
45     // Tests an rvalue uses the copy constructor.
46     // Since implementations are allowed to add additional constructors this is
47     // a libc++ specific test.
48     std::chrono::leap_second b = std::move(a);
49 
50     //  operator== only compares the date member.
51     assert(a.date() == b.date());
52     assert(a.value() == b.value());
53   }
54   // libc++ does not provide a default constructor.
55   static_assert(!std::is_default_constructible_v<std::chrono::leap_second>);
56 #endif // _LIBCPP_VERSION
57 
58   return true;
59 }
60 
61 int main(int, const char**) {
62   static_assert(std::copy_constructible<std::chrono::leap_second>);
63 
64   test();
65   static_assert(test());
66 
67   return 0;
68 }
69