Mercurial > hg > CbC > CbC_gcc
comparison libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc @ 152:2b5abeee2509
update gcc11
author | anatofuz |
---|---|
date | Mon, 25 May 2020 07:50:57 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
145:1830386684a0 | 152:2b5abeee2509 |
---|---|
1 // Copyright (C) 2018-2020 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-options "-std=gnu++2a" } | |
19 // { dg-do compile { target c++2a } } | |
20 | |
21 #include <bit> | |
22 #include <limits> | |
23 | |
24 template<typename UInt> | |
25 constexpr auto | |
26 test(UInt x) | |
27 -> decltype(std::bit_floor(x)) | |
28 { | |
29 static_assert( noexcept(std::bit_floor(x)) ); | |
30 | |
31 static_assert( std::bit_floor(UInt(0)) == 0 ); | |
32 static_assert( std::bit_floor(UInt(1)) == 1 ); | |
33 static_assert( std::bit_floor(UInt(2)) == 2 ); | |
34 static_assert( std::bit_floor(UInt(3)) == 2 ); | |
35 static_assert( std::bit_floor(UInt(4)) == 4 ); | |
36 static_assert( std::bit_floor(UInt(0x11)) == 0x10 ); | |
37 static_assert( std::bit_floor(UInt(0x20)) == 0x20 ); | |
38 | |
39 if constexpr (std::numeric_limits<UInt>::digits > 8) | |
40 { | |
41 static_assert( std::bit_floor(UInt(0x201)) == 0x200 ); | |
42 static_assert( std::bit_floor(UInt(0x8ff)) == 0x800 ); | |
43 static_assert( std::bit_floor(UInt(0x1000)) == 0x1000 ); | |
44 } | |
45 | |
46 if constexpr (std::numeric_limits<UInt>::digits > 32) | |
47 { | |
48 static_assert( std::bit_floor(UInt(0xabcdef)) == 0x800000 ); | |
49 static_assert( std::bit_floor(UInt(0x1000000)) == 0x1000000 ); | |
50 static_assert( std::bit_floor(UInt(0x1000001)) == 0x1000000 ); | |
51 } | |
52 | |
53 if constexpr (std::numeric_limits<UInt>::digits > 64) | |
54 { | |
55 static_assert( std::bit_floor(UInt(1) << 64) == (UInt(1) << 64) ); | |
56 static_assert( std::bit_floor(UInt(3) << 64) == (UInt(2) << 64) ); | |
57 } | |
58 | |
59 return true; | |
60 } | |
61 | |
62 static_assert( test( (unsigned char)0 ) ); | |
63 static_assert( test( (unsigned short)0 ) ); | |
64 static_assert( test( (unsigned int)0 ) ); | |
65 static_assert( test( (unsigned long)0 ) ); | |
66 static_assert( test( (unsigned long long)0 ) ); | |
67 | |
68 // std::bit_floor(T) shall not participate in overload resolution | |
69 // unless T is an unsigned integer type. | |
70 struct X { constexpr bool did_not_match() { return true; } }; | |
71 constexpr X test(...) { return X{}; } | |
72 static_assert( test( (bool)0 ).did_not_match() ); | |
73 static_assert( test( (char)0 ).did_not_match() ); | |
74 static_assert( test( (int)0 ).did_not_match() ); | |
75 static_assert( test( (char16_t)0 ).did_not_match() ); | |
76 static_assert( test( (float)0 ).did_not_match() ); | |
77 static_assert( test( (void*)0 ).did_not_match() ); | |
78 static_assert( test( X{} ).did_not_match() ); | |
79 enum E : unsigned { e }; | |
80 static_assert( test( e ).did_not_match() ); | |
81 | |
82 #if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128 | |
83 static_assert( test( (unsigned __int128)0 ) ); | |
84 static_assert( test( (__int128)0 ).did_not_match() ); | |
85 #endif | |
86 #if defined(__GLIBCXX_TYPE_INT_N_0) | |
87 static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) ); | |
88 static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() ); | |
89 #endif | |
90 #if defined(__GLIBCXX_TYPE_INT_N_1) | |
91 static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) ); | |
92 static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() ); | |
93 #endif | |
94 #if defined(__GLIBCXX_TYPE_INT_N_2) | |
95 static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) ); | |
96 static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() ); | |
97 #endif | |
98 | |
99 #include <cstddef> | |
100 static_assert( test( (std::byte)0 ).did_not_match() ); |