When we use the ENUM_CLASS() macro on platforms that don't support C++11 strong enums, ENUM_CLASS will be implemented using the EnumClass template. Currently, if we declare an enum list like this (without C++11 support): ENUM_CLASS(MyEnum) { Enum1, Enum2 } ENUM_CLASS_END(MyEnum); ... and we use it like this: void foo(MyEnum value) { switch(value) { // <========== Compilation error. case Enum1: // do something. case Enum2: // do something else. } } In this example, the switch statement will result in a compilation error. To fix this, EnumClass needs to add a cast operator for Value (where Value is the type of the enumerated values): operator Value() { return m_value; } In addition, we also need to add the following comparison operators: bool operator==(const Value value) { return m_value == value; } bool operator!=(const Value value) { return m_value != value; } bool operator<(const Value value) { return m_value < value; } bool operator<=(const Value value) { return m_value <= value; } bool operator>(const Value value) { return m_value > value; } bool operator>=(const Value value) { return m_value >= value; } Note: the EnumClass template already has comparison operators for comparing against another EnumClass. It also has a conversion constructor that takes a Value argument. The reason for adding these comparison operators that compare against a Value is because when an instance of EnumClass is compared against a Value (or an int), there is an ambiguity in terms of how the C++ compiler can realize that comparison. Here are the 2 ways: 1. Convert the EnumClass to a Value (i.e. int) using the cast operator, and then do an int comparison. 2. Convert the other int value int an EnumClass instance, and then use one of the pre-existing comparison operators to do the comparison. By adding these comparison operators that take a Value argument, we provide an explicit approach to compare between an EnumClass and a Value, and therefore removed the ambiguity above.
Created attachment 186751 [details] the fix.
Reviewed by Sam. Landed in r141965: <http://trac.webkit.org/changeset/141965>.