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