• 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{10};
28     if (static_cast<unsigned>(--m1) != 9) return false;
29     if (static_cast<unsigned>(m1--) != 9) return false;
30     if (static_cast<unsigned>(m1)   != 8) return false;
31     return true;
32 }
33 
main()34 int main()
35 {
36     using month = std::chrono::month;
37 
38     ASSERT_NOEXCEPT(--(std::declval<month&>())  );
39     ASSERT_NOEXCEPT(  (std::declval<month&>())--);
40 
41     ASSERT_SAME_TYPE(month , decltype(  std::declval<month&>()--));
42     ASSERT_SAME_TYPE(month&, decltype(--std::declval<month&>()  ));
43 
44     static_assert(testConstexpr<month>(), "");
45 
46     for (unsigned i = 10; i <= 20; ++i)
47     {
48         month month(i);
49         assert(static_cast<unsigned>(--month) == i - 1);
50         assert(static_cast<unsigned>(month--) == i - 1);
51         assert(static_cast<unsigned>(month)   == i - 2);
52     }
53 }
54