op_mod=rep.pass.cpp 1.1 KB

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