1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10 
11 // <chrono>
12 // class year;
13 
14 // constexpr year operator+() const noexcept;
15 // constexpr year operator-() const noexcept;
16 
17 #include <chrono>
18 #include <type_traits>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
23 template <typename Y>
testConstexpr()24 constexpr bool testConstexpr()
25 {
26     Y y1{1};
27     if (static_cast<int>(+y1) !=  1) return false;
28     if (static_cast<int>(-y1) != -1) return false;
29     return true;
30 }
31 
main()32 int main()
33 {
34     using year  = std::chrono::year;
35 
36     ASSERT_NOEXCEPT(+std::declval<year>());
37     ASSERT_NOEXCEPT(-std::declval<year>());
38 
39     ASSERT_SAME_TYPE(year, decltype(+std::declval<year>()));
40     ASSERT_SAME_TYPE(year, decltype(-std::declval<year>()));
41 
42     static_assert(testConstexpr<year>(), "");
43 
44     for (int i = 10000; i <= 10020; ++i)
45     {
46         year year(i);
47         assert(static_cast<int>(+year) ==  i);
48         assert(static_cast<int>(-year) == -i);
49     }
50 }
51