[SimplifyCFG] Always allow hoisting if all instructions match. (#97158)
[llvm-project.git] / libcxx / test / std / time / time.duration / time.duration.nonmember / op_times_rep.pass.cpp
blobd7c8c2da3c3251a5b338a3c3de82362bbc8ba0aa
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 //===----------------------------------------------------------------------===//
9 // <chrono>
11 // duration
13 // template <class Rep1, class Period, class Rep2>
14 // constexpr
15 // duration<typename common_type<Rep1, Rep2>::type, Period>
16 // operator*(const duration<Rep1, Period>& d, const Rep2& s);
18 // template <class Rep1, class Period, class Rep2>
19 // constexpr
20 // duration<typename common_type<Rep1, Rep2>::type, Period>
21 // operator*(const Rep1& s, const duration<Rep2, Period>& d);
23 #include <chrono>
24 #include <cassert>
26 #include "test_macros.h"
27 #include "../../rep.h"
29 int main(int, char**) {
31 std::chrono::nanoseconds ns(3);
32 ns = ns * 5;
33 assert(ns.count() == 15);
34 ns = 6 * ns;
35 assert(ns.count() == 90);
38 #if TEST_STD_VER >= 11
40 constexpr std::chrono::nanoseconds ns(3);
41 constexpr std::chrono::nanoseconds ns2 = ns * 5;
42 static_assert(ns2.count() == 15, "");
43 constexpr std::chrono::nanoseconds ns3 = 6 * ns;
44 static_assert(ns3.count() == 18, "");
46 #endif
48 #if TEST_STD_VER >= 11
49 { // This is related to PR#41130
50 typedef std::chrono::nanoseconds Duration;
51 Duration d(5);
52 NotARep n;
53 ASSERT_SAME_TYPE(Duration, decltype(d * n));
54 ASSERT_SAME_TYPE(Duration, decltype(n * d));
55 d = d * n;
56 assert(d.count() == 5);
57 d = n * d;
58 assert(d.count() == 5);
61 std::chrono::duration<int> d(8);
62 RepConstConvertibleLWG3050 x;
65 auto r = d * x;
66 assert(r.count() == 16);
67 ASSERT_SAME_TYPE(std::chrono::duration<long>, decltype(r));
70 auto r = x * d;
71 assert(r.count() == 16);
72 ASSERT_SAME_TYPE(std::chrono::duration<long>, decltype(r));
75 #endif // TEST_STD_VER >= 11
77 return 0;