| 1 | // Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-do compile { target c++11 } } |
| 19 | |
| 20 | #include <chrono> |
| 21 | |
| 22 | void |
| 23 | test01() |
| 24 | { |
| 25 | using namespace std::chrono; |
| 26 | using std::exa; |
| 27 | |
| 28 | // LWG 2094 |
| 29 | // duration conversion overflow shouldn't participate in overload resolution |
| 30 | bool f(milliseconds); |
| 31 | void f(seconds); |
| 32 | duration<int,exa> r(1); |
| 33 | f(r); |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | test02() |
| 38 | { |
| 39 | struct Number |
| 40 | { |
| 41 | explicit |
| 42 | Number(int t = 0) : i(t) |
| 43 | { } |
| 44 | |
| 45 | int i = 0; |
| 46 | |
| 47 | Number& operator+=(Number n) { i += n.i; return *this; } |
| 48 | Number& operator-=(Number n) { i -= n.i; return *this; } |
| 49 | Number& operator*=(Number n) { i *= n.i; return *this; } |
| 50 | Number& operator/=(Number n) { i /= n.i; return *this; } |
| 51 | Number& operator%=(Number n) { i %= n.i; return *this; } |
| 52 | |
| 53 | Number operator+(Number n) { return Number{ i + n.i }; } |
| 54 | Number operator-(Number n) { return Number{ i - n.i }; } |
| 55 | Number operator*(Number n) { return Number{ i * n.i }; } |
| 56 | Number operator/(Number n) { return Number{ i / n.i }; } |
| 57 | Number operator%(Number n) { return Number{ i % n.i }; } |
| 58 | }; |
| 59 | |
| 60 | using std::chrono::duration; |
| 61 | |
| 62 | static_assert( ! std::is_constructible<duration<int>, duration<Number>>(), |
| 63 | "duration(const duration<R2, P2>&) constrained on R2 -> R conversion" ); |
| 64 | } |