Marshall Clow | a5c3485 | 2019-07-01 23:00:32 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Louis Dionne | 31cbe0f | 2020-06-01 10:38:23 -0400 | [diff] [blame^] | 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
Marshall Clow | a5c3485 | 2019-07-01 23:00:32 +0000 | [diff] [blame] | 10 | |
| 11 | // template <class T> |
| 12 | // constexpr T ceil2(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> |
| 29 | constexpr bool toobig() |
| 30 | { |
| 31 | return 0 == std::ceil2(std::numeric_limits<T>::max()); |
| 32 | } |
| 33 | |
| 34 | int main() |
| 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 | } |