LLVM_DECLARE_ENUM_AS_BITMASK can be used to declare an enum type as a bit set, so that bitwise operation on such enum does not require static_cast.

Synopsis

Declared in <llvm/ADT/BitmaskEnum.h>

#define LLVM_DECLARE_ENUM_AS_BITMASK(Enum, LargestValue)

Description

enum MyEnum { E1 = 1, E2 = 2, E3 = 4, E4 = 8 };
LLVM_DECLARE_ENUM_AS_BITMASK(MyEnum, E4);

void Foo() {
  MyEnum A = (E1 | E2) & E3 ^ ~E4; // No static_cast
}

The second parameter to LLVM_DECLARE_ENUM_AS_BITMASK specifies the largest bit value of the enum type.

LLVM_DECLARE_ENUM_AS_BITMASK should be used in llvm namespace.

This a non‐intrusive alternative for LLVM_MARK_AS_BITMASK_ENUM. It allows declaring more than one non‐scoped enumerations as bitmask types in the same scope. Otherwise it provides the same functionality as LLVM_MARK_AS_BITMASK_ENUM.

Created with MrDocs