annotate libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_ceil_neg.cc @ 19:2b5abeee2509 default tip

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
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // Copyright (C) 2019-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 -D_GLIBCXX_ASSERTIONS" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 // { dg-do run { target c++2a } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 // { dg-xfail-run-if "__glibcxx_assert in bit_ceil should fail" { *-*-* } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 #include <bit>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 #include <limits>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 // P1355R2: not a constant expression if the result is not representable
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 template<auto N, typename = void>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 struct bit_ceil_valid
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 : std::false_type { };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 template<auto N>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 struct bit_ceil_valid<N, std::void_t<char[(std::bit_ceil(N), 1)]>>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 : std::true_type { };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 template<typename T>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36 constexpr T max = std::numeric_limits<T>::max();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 template<typename T>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38 constexpr T maxpow2 = T(1) << (std::numeric_limits<T>::digits - 1);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 static_assert( bit_ceil_valid<maxpow2<unsigned char>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 static_assert( !bit_ceil_valid<maxpow2<unsigned char> + (unsigned char)1>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 static_assert( !bit_ceil_valid<max<unsigned char>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 static_assert( !bit_ceil_valid<max<unsigned char> - (unsigned char)1>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 static_assert( bit_ceil_valid<maxpow2<unsigned short>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 static_assert( !bit_ceil_valid<maxpow2<unsigned short> + (unsigned short)1>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 static_assert( !bit_ceil_valid<max<unsigned short>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 static_assert( !bit_ceil_valid<max<unsigned short> - (unsigned short)1>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 static_assert( bit_ceil_valid<maxpow2<unsigned int>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 static_assert( !bit_ceil_valid<maxpow2<unsigned int> + 1u>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 static_assert( !bit_ceil_valid<max<unsigned int>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 static_assert( !bit_ceil_valid<max<unsigned int> - 1u>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 static_assert( bit_ceil_valid<maxpow2<unsigned long>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 static_assert( !bit_ceil_valid<maxpow2<unsigned long> + 1ul>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 static_assert( !bit_ceil_valid<max<unsigned long>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 static_assert( !bit_ceil_valid<max<unsigned long> - 1ul>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 static_assert( bit_ceil_valid<maxpow2<unsigned long long>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 static_assert( !bit_ceil_valid<maxpow2<unsigned long long> + 1ull>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 static_assert( !bit_ceil_valid<max<unsigned long long>>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 static_assert( !bit_ceil_valid<max<unsigned long long> - 1ull>() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 test01()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 std::bit_ceil( maxpow2<unsigned> + 1u ); // should fail __glibcxx_assert
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 int main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 }