1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
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 <cstdint>
19 #include <limits>
20 #include <cassert>
21
22 #include "test_macros.h"
23
24 class A{};
25 enum E1 : unsigned char { rEd };
26 enum class E2 : unsigned char { red };
27
28 template <typename T>
toobig()29 constexpr bool toobig()
30 {
31 return 0 == std::bit_ceil(std::numeric_limits<T>::max());
32 }
33
main(int,char **)34 int main(int, char**)
35 {
36 // Make sure we generate a compile-time error for UB
37 static_assert(toobig<unsigned char>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
38 static_assert(toobig<unsigned short>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
39 static_assert(toobig<unsigned>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
40 static_assert(toobig<unsigned long>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
41 static_assert(toobig<unsigned long long>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
42
43 static_assert(toobig<uint8_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
44 static_assert(toobig<uint16_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
45 static_assert(toobig<uint32_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
46 static_assert(toobig<uint64_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
47 static_assert(toobig<size_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
48 static_assert(toobig<uintmax_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
49 static_assert(toobig<uintptr_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
50
51 return 0;
52 }
53