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