• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <chrono>
10 
11 // time_point
12 
13 // template <class Clock, class Duration1, class Rep2, class Period2>
14 //   time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
15 //   operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
16 
17 #include <chrono>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
22 template <class D>
test2739()23 void test2739()  // LWG2739
24 {
25     typedef std::chrono::time_point<std::chrono::system_clock> TimePoint;
26     typedef std::chrono::duration<D> Dur;
27     const Dur d(5);
28     TimePoint t0 = std::chrono::system_clock::from_time_t(200);
29     TimePoint t1 = t0 - d;
30     assert(t1 < t0);
31 }
32 
main(int,char **)33 int main(int, char**)
34 {
35     typedef std::chrono::system_clock Clock;
36     typedef std::chrono::milliseconds Duration1;
37     typedef std::chrono::microseconds Duration2;
38     {
39     std::chrono::time_point<Clock, Duration1> t1(Duration1(3));
40     std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
41     assert(t2.time_since_epoch() == Duration2(2995));
42     }
43 #if TEST_STD_VER > 11
44     {
45     constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3));
46     constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
47     static_assert(t2.time_since_epoch() == Duration2(2995), "");
48     }
49 #endif
50     test2739<int32_t>();
51     test2739<uint32_t>();
52 
53   return 0;
54 }
55