[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.cal / time.cal.ymwd / time.cal.ymwd.nonmembers / plus.pass.cpp
blob1601e8fecb7a4b66a794b0c2c85cc01509ab5137
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // <chrono>
11 // class year_month_weekday;
13 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const months& dm) noexcept;
14 // Returns: (ymd.year() / ymd.month() + dm) / ymd.day().
16 // constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymd) noexcept;
17 // Returns: ymd + dm.
20 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const years& dy) noexcept;
21 // Returns: (ymd.year() + dy) / ymd.month() / ymd.day().
23 // constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymd) noexcept;
24 // Returns: ym + dm.
26 #include <chrono>
27 #include <type_traits>
28 #include <cassert>
30 #include "test_macros.h"
32 using year = std::chrono::year;
33 using month = std::chrono::month;
34 using weekday = std::chrono::weekday;
35 using weekday_indexed = std::chrono::weekday_indexed;
36 using year_month_weekday = std::chrono::year_month_weekday;
37 using years = std::chrono::years;
38 using months = std::chrono::months;
40 constexpr bool test() {
41 constexpr weekday Tuesday = std::chrono::Tuesday;
42 constexpr month January = std::chrono::January;
44 { // year_month_weekday + months (and switched)
45 year_month_weekday ym{year{1234}, January, weekday_indexed{Tuesday, 3}};
46 for (int i = 0; i <= 10; ++i) {
47 year_month_weekday ymwd1 = ym + months{i};
48 year_month_weekday ymwd2 = months{i} + ym;
49 assert(static_cast<int>(ymwd1.year()) == 1234);
50 assert(static_cast<int>(ymwd2.year()) == 1234);
51 assert(ymwd1.month() == month(1 + i));
52 assert(ymwd2.month() == month(1 + i));
53 assert(ymwd1.weekday() == Tuesday);
54 assert(ymwd2.weekday() == Tuesday);
55 assert(ymwd1.index() == 3);
56 assert(ymwd2.index() == 3);
57 assert(ymwd1 == ymwd2);
59 // Test the year wraps around.
60 for (int i = 12; i <= 15; ++i) {
61 year_month_weekday ymwd1 = ym + months{i};
62 year_month_weekday ymwd2 = months{i} + ym;
63 assert(static_cast<int>(ymwd1.year()) == 1235);
64 assert(static_cast<int>(ymwd2.year()) == 1235);
65 assert(ymwd1.month() == month(1 + i - 12));
66 assert(ymwd2.month() == month(1 + i - 12));
67 assert(ymwd1.weekday() == Tuesday);
68 assert(ymwd2.weekday() == Tuesday);
69 assert(ymwd1.index() == 3);
70 assert(ymwd2.index() == 3);
71 assert(ymwd1 == ymwd2);
75 { // year_month_weekday + years (and switched)
76 year_month_weekday ym{year{1234}, std::chrono::January, weekday_indexed{Tuesday, 3}};
77 for (int i = 0; i <= 10; ++i) {
78 year_month_weekday ymwd1 = ym + years{i};
79 year_month_weekday ymwd2 = years{i} + ym;
80 assert(static_cast<int>(ymwd1.year()) == i + 1234);
81 assert(static_cast<int>(ymwd2.year()) == i + 1234);
82 assert(ymwd1.month() == January);
83 assert(ymwd2.month() == January);
84 assert(ymwd1.weekday() == Tuesday);
85 assert(ymwd2.weekday() == Tuesday);
86 assert(ymwd1.index() == 3);
87 assert(ymwd2.index() == 3);
88 assert(ymwd1 == ymwd2);
92 return true;
95 int main(int, char**) {
96 // year_month_weekday + months (and switched)
97 ASSERT_NOEXCEPT(std::declval<year_month_weekday>() + std::declval<months>());
98 ASSERT_NOEXCEPT(std::declval<months>() + std::declval<year_month_weekday>());
100 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() + std::declval<months>()));
101 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<months>() + std::declval<year_month_weekday>()));
103 // year_month_weekday + years (and switched)
104 ASSERT_NOEXCEPT(std::declval<year_month_weekday>() + std::declval<years>());
105 ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year_month_weekday>());
107 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() + std::declval<years>()));
108 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<years>() + std::declval<year_month_weekday>()));
110 test();
111 static_assert(test());
113 return 0;