| 1 | // { dg-do compile { target c++17 } } |
| 2 | #include <numeric> |
| 3 | #include <climits> |
| 4 | |
| 5 | // PR libstdc++/105844 |
| 6 | |
| 7 | // |INT_MIN| can be represented in common_type_t<int, unsigned> i.e. unsigned. |
| 8 | static_assert( std::gcd(INT_MIN, 2u) == 2 ); |
| 9 | static_assert( std::gcd(2u, INT_MIN) == 2 ); |
| 10 | |
| 11 | // |LLONG_MIN| can be represented in unsigned long long. |
| 12 | static_assert( std::gcd(LLONG_MIN, 2ull) == 2 ); |
| 13 | static_assert( std::gcd(2ull, LLONG_MIN) == 2 ); |
| 14 | |
| 15 | // But |INT_MIN| cannot be represented in common_type<int, int> i.e. int. |
| 16 | constexpr int a = std::gcd(INT_MIN, 1); // { dg-error "in .constexpr." } |
| 17 | constexpr int b = std::gcd(1, INT_MIN); // { dg-error "in .constexpr." } |
| 18 | |
| 19 | // And |LLONG_MIN| cannot be represented in long. |
| 20 | constexpr long long c = std::gcd(LLONG_MIN, 1); // { dg-error "in .constexpr." } |
| 21 | constexpr long long d = std::gcd(1, LLONG_MIN); // { dg-error "in .constexpr." } |
| 22 | |
| 23 | // { dg-error "overflow" "" { target *-*-* } 0 } |