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 year;
12
13 // constexpr year operator+(const year& x, const years& y) noexcept;
14 // Returns: year(int{x} + y.count()).
15 //
16 // constexpr year operator+(const years& x, const year& y) noexcept;
17 // Returns: y + x
18
19
20 #include <chrono>
21 #include <type_traits>
22 #include <cassert>
23
24 #include "test_macros.h"
25
26 template <typename Y, typename Ys>
testConstexpr()27 constexpr bool testConstexpr()
28 {
29 Y y{1001};
30 Ys offset{23};
31 if (y + offset != Y{1024}) return false;
32 if (offset + y != Y{1024}) return false;
33 return true;
34 }
35
main(int,char **)36 int main(int, char**)
37 {
38 using year = std::chrono::year;
39 using years = std::chrono::years;
40
41 ASSERT_NOEXCEPT( std::declval<year>() + std::declval<years>());
42 ASSERT_SAME_TYPE(year, decltype(std::declval<year>() + std::declval<years>()));
43
44 ASSERT_NOEXCEPT( std::declval<years>() + std::declval<year>());
45 ASSERT_SAME_TYPE(year, decltype(std::declval<years>() + std::declval<year>()));
46
47 static_assert(testConstexpr<year, years>(), "");
48
49 year y{1223};
50 for (int i = 1100; i <= 1110; ++i)
51 {
52 year y1 = y + years{i};
53 year y2 = years{i} + y;
54 assert(y1 == y2);
55 assert(static_cast<int>(y1) == i + 1223);
56 assert(static_cast<int>(y2) == i + 1223);
57 }
58
59 return 0;
60 }
61