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