| 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s |
| 2 | template<typename T> int force_same(T, T); |
| 3 | |
| 4 | // C++ [dcl.enum]p5: |
| 5 | // [...] If the underlying type is not fixed, the type of each enumerator is |
| 6 | // the type of its initializing value: |
| 7 | // - If an initializer is specified for an enumerator, the initializing |
| 8 | // value has the same type as the expression. |
| 9 | enum Bullet1 { |
| 10 | Bullet1Val1 = 'a', |
| 11 | Bullet1Val2 = 10u, |
| 12 | Bullet1Val1IsChar = sizeof(force_same(Bullet1Val1, char(0))), |
| 13 | Bullet1Val2IsUnsigned = sizeof(force_same(Bullet1Val2, unsigned(0))) |
| 14 | }; |
| 15 | |
| 16 | // - If no initializer is specified for the first enumerator, the |
| 17 | // initializing value has an unspecified integral type. |
| 18 | enum Bullet2 { |
| 19 | Bullet2Val, |
| 20 | Bullet2ValIsInt = sizeof(force_same(Bullet2Val, int(0))) |
| 21 | }; |
| 22 | |
| 23 | // - Otherwise the type of the initializing value is the same as the type |
| 24 | // of the initializing value of the preceding enumerator unless the |
| 25 | // incremented value is not representable in that type, in which case the |
| 26 | // type is an unspecified integral type sufficient to contain the |
| 27 | // incremented value. If no such type exists, the program is ill-formed. |
| 28 | enum Bullet3a { |
| 29 | Bullet3aVal1 = 17, |
| 30 | Bullet3aVal2, |
| 31 | Bullet3aVal2IsInt = sizeof(force_same(Bullet3aVal2, int(0))), |
| 32 | Bullet3aVal3 = 2147483647, |
| 33 | Bullet3aVal3IsInt = sizeof(force_same(Bullet3aVal3, int(0))), |
| 34 | Bullet3aVal4, |
| 35 | Bullet3aVal4IsUnsigned = sizeof(force_same(Bullet3aVal4, 0ul)) |
| 36 | }; |
| 37 | |
| 38 | enum Bullet3b { |
| 39 | Bullet3bVal1 = 17u, |
| 40 | Bullet3bVal2, |
| 41 | Bullet3bVal2IsInt = sizeof(force_same(Bullet3bVal2, 0u)), |
| 42 | Bullet3bVal3 = 2147483647u, |
| 43 | Bullet3bVal3IsInt = sizeof(force_same(Bullet3bVal3, 0u)), |
| 44 | Bullet3bVal4, |
| 45 | Bullet3bVal4IsUnsigned = sizeof(force_same(Bullet3bVal4, 0ul)) |
| 46 | }; |
| 47 | |
| 48 | enum Bullet3c { |
| 49 | Bullet3cVal1 = 0xFFFFFFFFFFFFFFFEull, |
| 50 | Bullet3cVal2, |
| 51 | Bullet3cVal3 // expected-warning{{not representable}} |
| 52 | }; |
| 53 | |
| 54 | // Following the closing brace of an enum-specifier, each enumerator has the |
| 55 | // type of its enumeration. |
| 56 | int array0[sizeof(force_same(Bullet3bVal3, Bullet3b(0)))? 1 : -1]; |
| 57 | |