enum.c revision a03aca82de5259846d4ef38db11b8116398d2222
1// RUN: clang %s -fsyntax-only -verify -pedantic 2enum e {A, 3 B = 42LL << 32, // expected-warning {{ISO C restricts enumerator values to range of 'int'}} 4 C = -4, D = 12456 }; 5 6enum f { a = -2147483648, b = 2147483647 }; // ok. 7 8enum g { // too negative 9 c = -2147483649, // expected-warning {{ISO C restricts enumerator values to range of 'int'}} 10 d = 2147483647 }; 11enum h { e = -2147483648, // too pos 12 f = 2147483648 // expected-warning {{ISO C restricts enumerator values to range of 'int'}} 13}; 14 15// minll maxull 16enum x // expected-warning {{enumeration values exceed range of largest integer}} 17{ y = -9223372036854775807LL-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}} 18z = 9223372036854775808ULL }; // expected-warning {{ISO C restricts enumerator values to range of 'int'}} 19 20int test() { 21 return sizeof(enum e) ; 22} 23 24enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}} 25 26int test2(int i) 27{ 28 ve + i; // expected-error{{invalid operands to binary expression}} 29} 30 31// PR2020 32union u0; // expected-note {{previous use is here}} 33enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}} 34 35 36// rdar://6095136 37extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}} 38 39void test4() { 40 for (; ve2;) // expected-error {{statement requires expression of scalar type}} 41 ; 42 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}} 43 44 for (; ;ve2) 45 ; 46 (void)ve2; 47 ve2; // expected-warning {{expression result unused}} 48} 49 50// PR2416 51enum someenum {}; // expected-warning {{use of empty enum extension}} 52 53// <rdar://problem/6093889> 54enum e0 { // expected-note {{previous definition is here}} 55 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}} 56}; 57 58// PR3173 59enum { PR3173A, PR3173B = PR3173A+50 }; 60 61// PR2753 62void foo() { 63 enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} 64 enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} 65} 66 67// <rdar://problem/6503878> 68typedef enum { X = 0 }; // expected-warning{{typedef requires a name}} 69 70 71enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}} 72 NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}} 73}; 74 75/// PR3688 76struct s1 { 77 enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}} 78}; 79 80enum e1 { YES, NO }; 81 82static enum e1 badfunc(struct s1 *q) { 83 return q->bar(); 84} 85