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