// Copyright (C) 2019-2025 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // . // { dg-options "-D_GLIBCXX_ASSERTIONS" } // { dg-do run { target c++20 } } // { dg-xfail-run-if "__glibcxx_assert in bit_ceil should fail" { *-*-* } } #include #include // P1355R2: not a constant expression if the result is not representable template struct bit_ceil_valid : std::false_type { }; template struct bit_ceil_valid> : std::true_type { }; template constexpr T max = std::numeric_limits::max(); template constexpr T maxpow2 = T(1) << (std::numeric_limits::digits - 1); static_assert( bit_ceil_valid>() ); static_assert( !bit_ceil_valid + (unsigned char)1>() ); static_assert( !bit_ceil_valid>() ); static_assert( !bit_ceil_valid - (unsigned char)1>() ); static_assert( bit_ceil_valid>() ); static_assert( !bit_ceil_valid + (unsigned short)1>() ); static_assert( !bit_ceil_valid>() ); static_assert( !bit_ceil_valid - (unsigned short)1>() ); static_assert( bit_ceil_valid>() ); static_assert( !bit_ceil_valid + 1u>() ); static_assert( !bit_ceil_valid>() ); static_assert( !bit_ceil_valid - 1u>() ); static_assert( bit_ceil_valid>() ); static_assert( !bit_ceil_valid + 1ul>() ); static_assert( !bit_ceil_valid>() ); static_assert( !bit_ceil_valid - 1ul>() ); static_assert( bit_ceil_valid>() ); static_assert( !bit_ceil_valid + 1ull>() ); static_assert( !bit_ceil_valid>() ); static_assert( !bit_ceil_valid - 1ull>() ); void test01() { std::bit_ceil( maxpow2 + 1u ); // should fail __glibcxx_assert } int main() { test01(); }