]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc
1 // Copyright (C) 2019-2020 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 ceil2 should fail" { *-*-* } }
24 // P1355R2: not a constant expression if the result is not representable
26 template<auto N
, typename
= void>
28 : std::false_type
{ };
31 struct ceil2_valid
<N
, std::void_t
<char[(std::ceil2(N
), 1)]>>
35 constexpr T max
= std::numeric_limits
<T
>::max();
37 constexpr T maxpow2
= T(1) << (std::numeric_limits
<T
>::digits
- 1);
39 static_assert( ceil2_valid
<maxpow2
<unsigned char>>() );
40 static_assert( !ceil2_valid
<maxpow2
<unsigned char> + (unsigned char)1>() );
42 static_assert( !ceil2_valid
<max
<unsigned char>>() );
43 static_assert( !ceil2_valid
<max
<unsigned char> - (unsigned char)1>() );
45 static_assert( ceil2_valid
<maxpow2
<unsigned short>>() );
46 static_assert( !ceil2_valid
<maxpow2
<unsigned short> + (unsigned short)1>() );
47 static_assert( !ceil2_valid
<max
<unsigned short>>() );
48 static_assert( !ceil2_valid
<max
<unsigned short> - (unsigned short)1>() );
50 static_assert( ceil2_valid
<maxpow2
<unsigned int>>() );
51 static_assert( !ceil2_valid
<maxpow2
<unsigned int> + 1u>() );
52 static_assert( !ceil2_valid
<max
<unsigned int>>() );
53 static_assert( !ceil2_valid
<max
<unsigned int> - 1u>() );
55 static_assert( ceil2_valid
<maxpow2
<unsigned long>>() );
56 static_assert( !ceil2_valid
<maxpow2
<unsigned long> + 1ul>() );
57 static_assert( !ceil2_valid
<max
<unsigned long>>() );
58 static_assert( !ceil2_valid
<max
<unsigned long> - 1ul>() );
60 static_assert( ceil2_valid
<maxpow2
<unsigned long long>>() );
61 static_assert( !ceil2_valid
<maxpow2
<unsigned long long> + 1ull>() );
62 static_assert( !ceil2_valid
<max
<unsigned long long>>() );
63 static_assert( !ceil2_valid
<max
<unsigned long long> - 1ull>() );
68 std::ceil2( maxpow2
<unsigned> + 1u ); // should fail __glibcxx_assert