enum.perms.pass.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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
  10. // <experimental/filesystem>
  11. // enum class perms;
  12. #include "filesystem_include.hpp"
  13. #include <type_traits>
  14. #include <cassert>
  15. #include <sys/stat.h>
  16. #include "test_macros.h"
  17. #include "check_bitmask_types.hpp"
  18. constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); }
  19. int main() {
  20. typedef fs::perms E;
  21. static_assert(std::is_enum<E>::value, "");
  22. // Check that E is a scoped enum by checking for conversions.
  23. typedef std::underlying_type<E>::type UT;
  24. static_assert(!std::is_convertible<E, UT>::value, "");
  25. static_assert(std::is_same<UT, unsigned >::value, ""); // Implementation detail
  26. typedef check_bitmask_type<E, E::group_all, E::owner_all> BitmaskTester;
  27. assert(BitmaskTester::check());
  28. static_assert(
  29. E::none == ME(0) &&
  30. E::owner_read == ME(0400) &&
  31. E::owner_write == ME(0200) &&
  32. E::owner_exec == ME(0100) &&
  33. E::owner_all == ME(0700) &&
  34. E::group_read == ME(040) &&
  35. E::group_write == ME(020) &&
  36. E::group_exec == ME(010) &&
  37. E::group_all == ME(070) &&
  38. E::others_read == ME(04) &&
  39. E::others_write == ME(02) &&
  40. E::others_exec == ME(01) &&
  41. E::others_all == ME(07) &&
  42. E::all == ME(0777) &&
  43. E::set_uid == ME(04000) &&
  44. E::set_gid == ME(02000) &&
  45. E::sticky_bit == ME(01000) &&
  46. E::mask == ME(07777) &&
  47. E::unknown == ME(0xFFFF) &&
  48. E::add_perms == ME(0x10000) &&
  49. E::remove_perms == ME(0x20000) &&
  50. E::symlink_nofollow == ME(0x40000),
  51. "Expected enumeration values do not match");
  52. }