Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/BitmaskEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
using ::llvm::BitmaskEnumDetail::operator^=; \
using ::llvm::BitmaskEnumDetail::operator<<=; \
using ::llvm::BitmaskEnumDetail::operator>>=; \
using ::llvm::BitmaskEnumDetail::operator!; \
/* Force a semicolon at the end of this macro. */ \
using ::llvm::BitmaskEnumDetail::any

Expand Down Expand Up @@ -141,6 +142,11 @@ constexpr unsigned bitWidth(uint64_t Value) {
return Value ? 1 + bitWidth(Value >> 1) : 0;
}

template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
constexpr bool operator!(E Val) {
return Val == static_cast<E>(0);
}

template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
constexpr bool any(E Val) {
return Val != static_cast<E>(0);
Expand Down
11 changes: 11 additions & 0 deletions llvm/unittests/ADT/BitmaskEnumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ TEST(BitmaskEnumTest, BitwiseNot) {
EXPECT_EQ(15, ~V0);
}

TEST(BitmaskEnumTest, BooleanNot) {
bool b0 = !F0;
EXPECT_TRUE(b0);

bool b1 = !(F1 & F2);
EXPECT_TRUE(b1);

bool b2 = !(F2 | F4);
EXPECT_FALSE(b2);
}

enum class FlagsClass {
F0 = 0,
F1 = 1,
Expand Down