xref: /llvm-project/libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp (revision a4422a51941bfcffc870d1e2fff682e5387f89c2)
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& operator=(const leap_second&) = default;
20 //
21 //   ...
22 // };
23 
24 #include <chrono>
25 #include <concepts>
26 #include <memory>
27 #include <type_traits>
28 #include <cassert>
29 
30 #include "test_chrono_leap_second.h"
31 
test()32 constexpr bool test() {
33   std::chrono::leap_second a =
34       test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1});
35   std::chrono::leap_second b =
36       test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{10}}, std::chrono::seconds{15});
37 
38   //  operator== only compares the date member.
39   assert(a.date() != b.date());
40   assert(a.value() != b.value());
41 
42   {
43     std::same_as<std::chrono::leap_second&> decltype(auto) result(b = a);
44     assert(std::addressof(result) == std::addressof(b));
45 
46     assert(a.date() == b.date());
47     assert(a.value() == b.value());
48   }
49 
50   {
51     // Tests an rvalue uses the copy assignment.
52     std::same_as<std::chrono::leap_second&> decltype(auto) result(b = std::move(a));
53     assert(std::addressof(result) == std::addressof(b));
54 
55     assert(a.date() == b.date());
56     assert(a.value() == b.value());
57   }
58 
59   return true;
60 }
61 
main(int,const char **)62 int main(int, const char**) {
63   static_assert(std::is_copy_assignable_v<std::chrono::leap_second>);
64 
65   test();
66   static_assert(test());
67 
68   return 0;
69 }
70