ceil2.fail.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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++98, c++03, c++11, c++14, c++17
  10. // template <class T>
  11. // constexpr T ceil2(T x) noexcept;
  12. // Remarks: This function shall not participate in overload resolution unless
  13. // T is an unsigned integer type
  14. #include <bit>
  15. #include <cstdint>
  16. #include <limits>
  17. #include <cassert>
  18. #include "test_macros.h"
  19. class A{};
  20. enum E1 : unsigned char { rEd };
  21. enum class E2 : unsigned char { red };
  22. template <typename T>
  23. constexpr bool toobig()
  24. {
  25. return 0 == std::ceil2(std::numeric_limits<T>::max());
  26. }
  27. int main()
  28. {
  29. // Make sure we generate a compile-time error for UB
  30. static_assert(toobig<unsigned char>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  31. static_assert(toobig<unsigned short>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  32. static_assert(toobig<unsigned>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  33. static_assert(toobig<unsigned long>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  34. static_assert(toobig<unsigned long long>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  35. static_assert(toobig<uint8_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  36. static_assert(toobig<uint16_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  37. static_assert(toobig<uint32_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  38. static_assert(toobig<uint64_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  39. static_assert(toobig<size_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  40. static_assert(toobig<uintmax_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  41. static_assert(toobig<uintptr_t>(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
  42. }