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