• 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 month;
13 
14 //  constexpr month& operator++() noexcept;
15 //  constexpr month operator++(int) noexcept;
16 
17 
18 #include <chrono>
19 #include <type_traits>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
24 template <typename M>
testConstexpr()25 constexpr bool testConstexpr()
26 {
27     M m1{1};
28     if (static_cast<unsigned>(++m1) != 2) return false;
29     if (static_cast<unsigned>(m1++) != 2) return false;
30     if (static_cast<unsigned>(m1)   != 3) return false;
31     return true;
32 }
33 
main()34 int main()
35 {
36     using month = std::chrono::month;
37     ASSERT_NOEXCEPT(++(std::declval<month&>())  );
38     ASSERT_NOEXCEPT(  (std::declval<month&>())++);
39 
40     ASSERT_SAME_TYPE(month , decltype(  std::declval<month&>()++));
41     ASSERT_SAME_TYPE(month&, decltype(++std::declval<month&>()  ));
42 
43     static_assert(testConstexpr<month>(), "");
44 
45     for (unsigned i = 0; i <= 10; ++i)
46     {
47         month month(i);
48         assert(static_cast<unsigned>(++month) == i + 1);
49         assert(static_cast<unsigned>(month++) == i + 1);
50         assert(static_cast<unsigned>(month)   == i + 2);
51     }
52 }
53