annotate libstdc++-v3/testsuite/20_util/integer_comparisons/in_range.cc @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
152
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // Copyright (C) 2020 Free Software Foundation, Inc.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 //
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 // This file is part of the GNU ISO C++ Library. This library is free
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 // software; you can redistribute it and/or modify it under the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 // terms of the GNU General Public License as published by the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 // Free Software Foundation; either version 3, or (at your option)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 // any later version.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 // This library is distributed in the hope that it will be useful,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 // GNU General Public License for more details.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 // You should have received a copy of the GNU General Public License along
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 // with this library; see the file COPYING3. If not see
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 // <http://www.gnu.org/licenses/>.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 // { dg-options "-std=gnu++2a" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 // { dg-do run { target c++2a } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 #include <utility>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 #include <limits>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 #include <testsuite_hooks.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 test01()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 unsigned int u = std::numeric_limits<unsigned int>::max();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 VERIFY( std::in_range<unsigned int>(u) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 VERIFY( !std::in_range<int>(u) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 int s = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 VERIFY( !std::in_range<unsigned int>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 s = std::numeric_limits<int>::max();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 VERIFY( std::in_range<unsigned int>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 constexpr bool
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38 test02()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 unsigned int u = std::numeric_limits<unsigned int>::max();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 if (std::in_range<int>(u))
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 throw 1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 int s = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 if (std::in_range<unsigned>(s))
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 throw 2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 s = std::numeric_limits<int>::max();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 if (!std::in_range<unsigned>(s))
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 throw 3;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 return true;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 test03()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 short ss = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 VERIFY( std::in_range<int>(ss) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 VERIFY( !std::in_range<unsigned>(ss) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 int s = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 VERIFY( std::in_range<short>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 VERIFY( !std::in_range<unsigned>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 VERIFY( !std::in_range<unsigned long>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 VERIFY( std::in_range<long>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 s = std::numeric_limits<short>::min() - 1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 VERIFY( !std::in_range<short>(s) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 unsigned int u = (unsigned int) -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 VERIFY( !std::in_range<int>(u) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 VERIFY( !std::in_range<unsigned short>(u) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 unsigned long ul = (unsigned long) -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 VERIFY( !std::in_range<unsigned short>(ul) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 VERIFY( std::in_range<unsigned long long>(ul) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 static_assert( test02() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 test03();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 }