]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_ceil_neg.cc
1 // Copyright (C) 2019-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a -D_GLIBCXX_ASSERTIONS" }
19 // { dg-do run { target c++2a } }
20 // { dg-xfail-run-if "__glibcxx_assert in bit_ceil should fail" { *-*-* } }
25 // P1355R2: not a constant expression if the result is not representable
27 template<auto N
, typename
= void>
29 : std::false_type
{ };
32 struct bit_ceil_valid
<N
, std::void_t
<char[(std::bit_ceil(N
), 1)]>>
36 constexpr T max
= std::numeric_limits
<T
>::max();
38 constexpr T maxpow2
= T(1) << (std::numeric_limits
<T
>::digits
- 1);
40 static_assert( bit_ceil_valid
<maxpow2
<unsigned char>>() );
41 static_assert( !bit_ceil_valid
<maxpow2
<unsigned char> + (unsigned char)1>() );
43 static_assert( !bit_ceil_valid
<max
<unsigned char>>() );
44 static_assert( !bit_ceil_valid
<max
<unsigned char> - (unsigned char)1>() );
46 static_assert( bit_ceil_valid
<maxpow2
<unsigned short>>() );
47 static_assert( !bit_ceil_valid
<maxpow2
<unsigned short> + (unsigned short)1>() );
48 static_assert( !bit_ceil_valid
<max
<unsigned short>>() );
49 static_assert( !bit_ceil_valid
<max
<unsigned short> - (unsigned short)1>() );
51 static_assert( bit_ceil_valid
<maxpow2
<unsigned int>>() );
52 static_assert( !bit_ceil_valid
<maxpow2
<unsigned int> + 1u>() );
53 static_assert( !bit_ceil_valid
<max
<unsigned int>>() );
54 static_assert( !bit_ceil_valid
<max
<unsigned int> - 1u>() );
56 static_assert( bit_ceil_valid
<maxpow2
<unsigned long>>() );
57 static_assert( !bit_ceil_valid
<maxpow2
<unsigned long> + 1ul>() );
58 static_assert( !bit_ceil_valid
<max
<unsigned long>>() );
59 static_assert( !bit_ceil_valid
<max
<unsigned long> - 1ul>() );
61 static_assert( bit_ceil_valid
<maxpow2
<unsigned long long>>() );
62 static_assert( !bit_ceil_valid
<maxpow2
<unsigned long long> + 1ull>() );
63 static_assert( !bit_ceil_valid
<max
<unsigned long long>>() );
64 static_assert( !bit_ceil_valid
<max
<unsigned long long> - 1ull>() );
69 std::bit_ceil( maxpow2
<unsigned> + 1u ); // should fail __glibcxx_assert