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: x + -y.
15 //
16 // constexpr years operator-(const year& x, const year& y) noexcept;
17 // Returns: If x.ok() == true and y.ok() == true, returns a value m in the range
18 // [years{0}, years{11}] satisfying y + m == x.
19 // Otherwise the value returned is unspecified.
20 // [Example: January - February == years{11}. —end example]
21
22 extern "C" int printf(const char *, ...);
23
24 #include <chrono>
25 #include <type_traits>
26 #include <cassert>
27
28 #include "test_macros.h"
29
30 template <typename Y, typename Ys>
testConstexpr()31 constexpr bool testConstexpr()
32 {
33 Y y{2313};
34 Ys offset{1006};
35 if (y - offset != Y{1307}) return false;
36 if (y - Y{1307} != offset) return false;
37 return true;
38 }
39
main(int,char **)40 int main(int, char**)
41 {
42 using year = std::chrono::year;
43 using years = std::chrono::years;
44
45 ASSERT_NOEXCEPT( std::declval<year>() - std::declval<years>());
46 ASSERT_SAME_TYPE(year , decltype(std::declval<year>() - std::declval<years>()));
47
48 ASSERT_NOEXCEPT( std::declval<year>() - std::declval<year>());
49 ASSERT_SAME_TYPE(years, decltype(std::declval<year>() - std::declval<year>()));
50
51 static_assert(testConstexpr<year, years>(), "");
52
53 year y{1223};
54 for (int i = 1100; i <= 1110; ++i)
55 {
56 year y1 = y - years{i};
57 years ys1 = y - year{i};
58 assert(static_cast<int>(y1) == 1223 - i);
59 assert(ys1.count() == 1223 - i);
60 }
61
62 return 0;
63 }
64