Debian Codegraph @

libstdc++-v3/testsuite/experimental/numeric/92978.cc

raw
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++14 } }
19
20 #include <experimental/numeric>
21 #include <limits.h>
22
23 void
24 test01()
25 {
26 // PR libstdc++/92978
27 static_assert( std::experimental::gcd(-120, 10U) == 10,
28 "mixed signed/unsigned" );
29 static_assert( std::experimental::gcd(120U, -10) == 10,
30 "mixed signed/unsigned" );
31
32 static_assert( std::experimental::lcm(-42, 21U) == 42U );
33 }
34
35 void
36 test02()
37 {
38 static_assert( std::experimental::gcd(INT_MIN, 0LL) == 1LL+INT_MAX,
39 "|INT_MIN| should not be undefined as long as it fits in the result" );
40 static_assert( std::experimental::gcd(0LL, INT_MIN) == 1LL+INT_MAX,
41 "|INT_MIN| should not be undefined" );
42 static_assert( std::experimental::gcd(INT_MIN, 0LL + INT_MIN) == 1LL + INT_MAX,
43 "|INT_MIN| should not be undefined" );
44 static_assert( std::experimental::gcd(INT_MIN, 1LL + INT_MAX) == 1LL + INT_MAX,
45 "|INT_MIN| should not be undefined" );
46 static_assert( std::experimental::gcd(SHRT_MIN, 1U + SHRT_MAX) == 1U + SHRT_MAX,
47 "|SHRT_MIN| should not be undefined" );
48 }