enum.c revision 64f7e258e9c43eefb7f82dfcd600abeed48dc395
1// RUN: %clang_cc1 %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// expected-error{{tentative definition has type 'enum gccForwardEnumExtension' that is never completed}} \ 26// expected-note{{forward declaration of 'enum gccForwardEnumExtension'}} 27 28int test2(int i) 29{ 30 ve + i; // expected-error{{invalid operands to binary expression}} 31} 32 33// PR2020 34union u0; // expected-note {{previous use is here}} 35enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}} 36 37 38// rdar://6095136 39extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}} 40 41void test4() { 42 for (; ve2;) // expected-error {{statement requires expression of scalar type}} 43 ; 44 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}} 45 46 for (; ;ve2) // expected-warning {{expression result unused}} 47 ; 48 (void)ve2; 49 ve2; // expected-warning {{expression result unused}} 50} 51 52// PR2416 53enum someenum {}; // expected-warning {{use of empty enum extension}} 54 55// <rdar://problem/6093889> 56enum e0 { // expected-note {{previous definition is here}} 57 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}} 58}; 59 60// PR3173 61enum { PR3173A, PR3173B = PR3173A+50 }; 62 63// PR2753 64void foo() { 65 enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} 66 enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} 67} 68 69// <rdar://problem/6503878> 70typedef enum { X = 0 }; // expected-warning{{typedef requires a name}} 71 72 73enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}} 74 NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}} 75}; 76 77/// PR3688 78struct s1 { 79 enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}} 80}; 81 82enum e1 { YES, NO }; 83 84static enum e1 badfunc(struct s1 *q) { 85 return q->bar(); 86} 87 88 89// Make sure we don't a.k.a. anonymous enums. 90typedef enum { 91 an_enumerator = 20 92} an_enum; 93// FIXME: why is this only a warning? 94char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'an_enum', expected 'char *'}} 95