op_mod=duration.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // <chrono>
  9. // duration
  10. // duration& operator%=(const duration& rhs)
  11. #include <chrono>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "../../rep.h"
  15. #if TEST_STD_VER > 14
  16. constexpr bool test_constexpr()
  17. {
  18. std::chrono::microseconds us1(11);
  19. std::chrono::microseconds us2(3);
  20. us1 %= us2;
  21. return us1.count() == 2;
  22. }
  23. #endif
  24. int main(int, char**)
  25. {
  26. {
  27. std::chrono::microseconds us1(11);
  28. std::chrono::microseconds us2(3);
  29. us1 %= us2;
  30. assert(us1.count() == 2);
  31. us1 %= std::chrono::milliseconds(3);
  32. assert(us1.count() == 2);
  33. }
  34. #if TEST_STD_VER > 14
  35. static_assert(test_constexpr(), "");
  36. #endif
  37. #if TEST_STD_VER >= 11
  38. { // This is PR#41130
  39. std::chrono::nanoseconds d(5);
  40. NotARep n;
  41. d %= n;
  42. assert(d.count() == 5);
  43. }
  44. #endif
  45. return 0;
  46. }