| 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 |
| 9 | |
| 10 | // <chrono> |
| 11 | // class month; |
| 12 | |
| 13 | // constexpr month& operator+=(const month& d) noexcept; |
| 14 | // constexpr month& operator-=(const month& d) noexcept; |
| 15 | |
| 16 | #include <chrono> |
| 17 | #include <cassert> |
| 18 | #include <type_traits> |
| 19 | #include <utility> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | constexpr bool test() { |
| 24 | using month = std::chrono::month; |
| 25 | using months = std::chrono::months; |
| 26 | |
| 27 | for (unsigned i = 1; i <= 10; ++i) { |
| 28 | month m(i); |
| 29 | int exp = i + 10; |
| 30 | while (exp > 12) |
| 31 | exp -= 12; |
| 32 | assert(static_cast<unsigned>(m += months{10}) == static_cast<unsigned>(exp)); |
| 33 | assert(static_cast<unsigned>(m) == static_cast<unsigned>(exp)); |
| 34 | assert(m.ok()); |
| 35 | } |
| 36 | |
| 37 | for (unsigned i = 1; i <= 10; ++i) { |
| 38 | month m(i); |
| 39 | int exp = i - 9; |
| 40 | while (exp < 1) |
| 41 | exp += 12; |
| 42 | assert(static_cast<unsigned>(m -= months{9}) == static_cast<unsigned>(exp)); |
| 43 | assert(static_cast<unsigned>(m) == static_cast<unsigned>(exp)); |
| 44 | assert(m.ok()); |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | int main(int, char**) { |
| 50 | using month = std::chrono::month; |
| 51 | using months = std::chrono::months; |
| 52 | |
| 53 | ASSERT_NOEXCEPT(std::declval<month&>() += std::declval<months&>()); |
| 54 | ASSERT_NOEXCEPT(std::declval<month&>() -= std::declval<months&>()); |
| 55 | ASSERT_SAME_TYPE(month&, decltype(std::declval<month&>() += std::declval<months&>())); |
| 56 | ASSERT_SAME_TYPE(month&, decltype(std::declval<month&>() -= std::declval<months&>())); |
| 57 | |
| 58 | test(); |
| 59 | static_assert(test()); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |