1 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
2 enum e {A,
3         B = 42LL << 32,        // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
4       C = -4, D = 12456 };
5 
6 enum f { a = -2147483648, b = 2147483647 }; // ok.
7 
8 enum g {  // too negative
9    c = -2147483649,         // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
10    d = 2147483647 };
11 enum h { e = -2147483648, // too pos
12    f = 2147483648,           // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
13   i = 0xFFFF0000 // expected-warning {{too large}}
14 };
15 
16 // minll maxull
17 enum 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'}}
19 z = 9223372036854775808ULL };    // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
20 
test()21 int test() {
22   return sizeof(enum e) ;
23 }
24 
25 enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}} \
26 // expected-error{{tentative definition has type 'enum gccForwardEnumExtension' that is never completed}} \
27 // expected-note{{forward declaration of 'enum gccForwardEnumExtension'}}
28 
test2(int i)29 int test2(int i)
30 {
31   ve + i; // expected-error{{invalid operands to binary expression}}
32 }
33 
34 // PR2020
35 union u0;    // expected-note {{previous use is here}}
36 enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
37 
38 
39 // rdar://6095136
40 extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
41 
test4()42 void test4() {
43   for (; ve2;) // expected-error {{statement requires expression of scalar type}}
44     ;
45   (_Bool)ve2;  // expected-error {{arithmetic or pointer type is required}}
46 
47   for (; ;ve2) // expected-warning {{expression result unused}}
48     ;
49   (void)ve2;
50   ve2;         // expected-warning {{expression result unused}}
51 }
52 
53 // PR2416
54 enum someenum {};  // expected-error {{use of empty enum}}
55 
56 // <rdar://problem/6093889>
57 enum e0 { // expected-note {{previous definition is here}}
58   E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
59 };
60 
61 // PR3173
62 enum { PR3173A, PR3173B = PR3173A+50 };
63 
64 // PR2753
foo()65 void foo() {
66   enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}}
67   enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}}
68 }
69 
70 // <rdar://problem/6503878>
71 typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
72 
73 
74 enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
75   NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
76 };
77 
78 /// PR3688
79 struct s1 {
80   enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
81 };
82 
83 enum e1 { YES, NO };
84 
badfunc(struct s1 * q)85 static enum e1 badfunc(struct s1 *q) {
86   return q->bar();
87 }
88 
89 
90 // Make sure we don't a.k.a. anonymous enums.
91 typedef enum {
92   an_enumerator = 20
93 } an_enum;
94 char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}}
95 
96 // PR4515
97 enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
98 int CheckPR4515[PR4515b==0?1:-1];
99 
100 // PR7911
101 extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward references to 'enum' types}}
PR7911F()102 void PR7911F() {
103   switch (PR7911V); // expected-error {{statement requires expression of integer type}}
104 }
105 
106 char test5[__has_feature(enumerator_attributes) ? 1 : -1];
107 
108 // PR8694
109 // rdar://8707031
PR8694(int * e)110 void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}}
111 {
112 }
113 
crash(enum E * e)114 void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
115                       // expected-warning {{ISO C forbids forward references to 'enum' types}}
116 {
117         PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}
118 }
119 
120 typedef enum { NegativeShort = (short)-1 } NegativeShortEnum;
121 int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
122 
123 // PR24610
124 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
125 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
126 
127 // PR28903
128 // In C it is valid to define tags inside enums.
129 struct PR28903 {
130   enum {
131     PR28903_A = (enum {
132       PR28903_B,
133       PR28903_C = PR28903_B
134     })0
135   };
136   int makeStructNonEmpty;
137 };
138 
139 static int EnumRedecl; // expected-note 2 {{previous definition is here}}
140 struct S {
141   enum {
142     EnumRedecl = 4 // expected-error {{redefinition of 'EnumRedecl'}}
143   } e;
144 };
145 
146 union U {
147   enum {
148     EnumRedecl = 5 // expected-error {{redefinition of 'EnumRedecl'}}
149   } e;
150 };
151 
152 enum PR15071 {
153   PR15071_One // expected-note {{previous definition is here}}
154 };
155 
156 struct EnumRedeclStruct {
157   enum {
158     PR15071_One // expected-error {{redefinition of enumerator 'PR15071_One'}}
159   } e;
160 };
161