xref: /llvm-project/libcxx/test/std/numerics/bit/bit.pow.two/bit_ceil.verify.cpp (revision 1ee41b415398cde51c055a7b1a4d419350e7038f)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // template <class T>
12 //   constexpr T bit_ceil(T x) noexcept;
13 
14 // Remarks: This function shall not participate in overload resolution unless
15 //          T is an unsigned integer type
16 
17 #include <bit>
18 #include <cassert>
19 #include <cstddef>
20 #include <cstdint>
21 #include <limits>
22 
23 class A{};
24 enum       E1 : unsigned char { rEd };
25 enum class E2 : unsigned char { red };
26 
27 template <typename T>
toobig()28 constexpr bool toobig()
29 {
30     return 0 == std::bit_ceil(std::numeric_limits<T>::max());
31 }
32 
main(int,char **)33 int main(int, char**)
34 {
35     // Make sure we generate a compile-time error for UB
36     static_assert(toobig<unsigned char>(),      ""); // expected-error {{static assertion expression is not an integral constant expression}}
37     static_assert(toobig<unsigned short>(),     ""); // expected-error {{static assertion expression is not an integral constant expression}}
38     static_assert(toobig<unsigned>(),           ""); // expected-error {{static assertion expression is not an integral constant expression}}
39     static_assert(toobig<unsigned long>(),      ""); // expected-error {{static assertion expression is not an integral constant expression}}
40     static_assert(toobig<unsigned long long>(), ""); // expected-error {{static assertion expression is not an integral constant expression}}
41 
42     static_assert(toobig<std::uint8_t>(), "");   // expected-error {{static assertion expression is not an integral constant expression}}
43     static_assert(toobig<std::uint16_t>(), "");  // expected-error {{static assertion expression is not an integral constant expression}}
44     static_assert(toobig<std::uint32_t>(), "");  // expected-error {{static assertion expression is not an integral constant expression}}
45     static_assert(toobig<std::uint64_t>(), "");  // expected-error {{static assertion expression is not an integral constant expression}}
46     static_assert(toobig<std::size_t>(), "");    // expected-error {{static assertion expression is not an integral constant expression}}
47     static_assert(toobig<std::uintmax_t>(), ""); // expected-error {{static assertion expression is not an integral constant expression}}
48     static_assert(toobig<std::uintptr_t>(), ""); // expected-error {{static assertion expression is not an integral constant expression}}
49 
50     return 0;
51 }
52