[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.cal / time.cal.ymd / time.cal.ymd.members / plus_minus_equal_month.pass.cpp
blob40db399b110b839f85a6ee32d1ff32c6c144d803
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_day;
13 // constexpr year_month_day& operator+=(const months& m) noexcept;
14 // constexpr year_month_day& operator-=(const months& m) noexcept;
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
20 #include "test_macros.h"
22 using year = std::chrono::year;
23 using month = std::chrono::month;
24 using day = std::chrono::day;
25 using year_month_day = std::chrono::year_month_day;
26 using months = std::chrono::months;
28 constexpr bool test() {
29 for (unsigned i = 0; i <= 10; ++i) {
30 year y{1234};
31 day d{23};
32 year_month_day ymd(y, month{i}, d);
34 ymd += months{2};
35 assert(ymd.year() == y);
36 assert(ymd.day() == d);
37 assert(static_cast<unsigned>((ymd).month()) == i + 2);
39 ymd -= months{1};
40 assert(ymd.year() == y);
41 assert(ymd.day() == d);
42 assert(static_cast<unsigned>((ymd).month()) == i + 1);
45 { // Validate the ok status when the day is not present in the new month.
46 year_month_day ymd{year{2020}, month{3}, day{31}};
47 ymd += months{1};
48 assert((ymd == year_month_day{year{2020}, month{4}, day{31}}));
49 assert(!ymd.ok());
51 ymd -= months{1};
52 assert((ymd == year_month_day{year{2020}, month{3}, day{31}}));
53 assert(ymd.ok());
56 { // Validate the ok status when the day becomes present in the new month.
57 year_month_day ymd{year{2020}, month{4}, day{31}};
58 assert(!ymd.ok());
60 ymd += months{1};
61 assert((ymd == year_month_day{year{2020}, month{5}, day{31}}));
62 assert(ymd.ok());
64 ymd -= months{2};
65 assert((ymd == year_month_day{year{2020}, month{3}, day{31}}));
66 assert(ymd.ok());
69 { // Test year wrapping
70 year_month_day ymd{year{2020}, month{4}, day{31}};
72 ymd += months{12};
73 assert((ymd == year_month_day{year{2021}, month{4}, day{31}}));
75 ymd -= months{12};
76 assert((ymd == year_month_day{year{2020}, month{4}, day{31}}));
79 return true;
82 int main(int, char**) {
83 ASSERT_NOEXCEPT(std::declval<year_month_day&>() += std::declval<months>());
84 ASSERT_NOEXCEPT(std::declval<year_month_day&>() -= std::declval<months>());
86 ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval<year_month_day&>() += std::declval<months>()));
87 ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval<year_month_day&>() -= std::declval<months>()));
89 test();
90 static_assert(test());
92 return 0;