• 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 day;
13 
14 //  constexpr day& operator++() noexcept;
15 //  constexpr day 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 D>
testConstexpr()25 constexpr bool testConstexpr()
26 {
27     D d1{1};
28     if (static_cast<unsigned>(++d1) != 2) return false;
29     if (static_cast<unsigned>(d1++) != 2) return false;
30     if (static_cast<unsigned>(d1)   != 3) return false;
31     return true;
32 }
33 
main()34 int main()
35 {
36     using day = std::chrono::day;
37     ASSERT_NOEXCEPT(++(std::declval<day&>())  );
38     ASSERT_NOEXCEPT(  (std::declval<day&>())++);
39 
40     ASSERT_SAME_TYPE(day , decltype(  std::declval<day&>()++));
41     ASSERT_SAME_TYPE(day&, decltype(++std::declval<day&>()  ));
42 
43     static_assert(testConstexpr<day>(), "");
44 
45     for (unsigned i = 10; i <= 20; ++i)
46     {
47         day day(i);
48         assert(static_cast<unsigned>(++day) == i + 1);
49         assert(static_cast<unsigned>(day++) == i + 1);
50         assert(static_cast<unsigned>(day)   == i + 2);
51     }
52 }
53