[cfe-dev] Question about enums with explicit enum-base
Jonathan Sauer
jonathan.sauer at gmx.de
Sun May 22 13:03:37 PDT 2011
Hello,
it is great that clang is gaining new C++0x features so quickly! Even seemingly "smaller" innovations like
the possibility to explicitely specify the underlying type of an enum make programming in C++ easier.
So I was experimenting with <enum-base> and stumbled upon the following:
enum e: unsigned int { // (A)
//enum e: unsigned short { // (B)
A,
B,
C
};
int main(int, char**)
{
e a = A;
return a > 0;
}
With line (A) active, the code compiles with clang r131844. With line (B) active, it results in: "use of
overloaded operator '>' is ambiguous (with operand types 'e' and 'int')". Followed by a long list of
built-in operators.
Now, FDIS 4.5p3 says that an enum types can be converted to its underlying type, in this case 'unsigned short'.
Furthermore, 5.9p2 says that "the usual arithmetic conversions" are performed for relational operators, i.e.
according to 5p9, for the enum above, the following is done:
1. Integral promotion to 'unsigned short' (4.5p3)
2. Conversion of 'unsigned short' to 'int' (5p9 item 5.4)
Judging from the error I got, though, it seems that clang does not perform the latter step. Is this the case
(and should I file a PR), or am I misreading the standard here?
Many thanks in advance,
Jonathan
More information about the cfe-dev
mailing list