is_error_code_enum.pass.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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
  10. // <system_error>
  11. // template <> struct is_error_code_enum<> : public false_type {};
  12. #include <system_error>
  13. #include <string>
  14. #include "test_macros.h"
  15. template <bool Expected, class T>
  16. void
  17. test()
  18. {
  19. static_assert((std::is_error_code_enum<T>::value == Expected), "");
  20. #if TEST_STD_VER > 14
  21. static_assert((std::is_error_code_enum_v<T> == Expected), "");
  22. #endif
  23. }
  24. class A {
  25. A();
  26. operator std::error_code () const { return std::error_code(); }
  27. };
  28. // Specialize the template for my class
  29. namespace std
  30. {
  31. template <>
  32. struct is_error_code_enum<A> : public std::true_type {};
  33. }
  34. int main(int, char**)
  35. {
  36. test<false, void>();
  37. test<false, int>();
  38. test<false, std::nullptr_t>();
  39. test<false, std::string>();
  40. test<true, A>();
  41. return 0;
  42. }