Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / enum.c
blobf8e380bd62d1eaf9c1a0a923c69a4df39a0c5a30
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 };
6 enum f { a = -2147483648, b = 2147483647 }; // ok.
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}}
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'}}
21 int test(void) {
22 return sizeof(enum e) ;
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'}}
29 int test2(int i)
31 ve + i; // expected-error{{invalid operands to binary expression}}
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}}
38 extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
40 void test4(void) {
41 for (; ve2;) // expected-error {{statement requires expression of scalar type}}
43 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
45 for (; ;ve2) // expected-warning {{expression result unused}}
47 (void)ve2;
48 ve2; // expected-warning {{expression result unused}}
51 // PR2416
52 enum someenum {}; // expected-error {{use of empty enum}}
54 enum e0 { // expected-note {{previous definition is here}}
55 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
58 // PR3173
59 enum { PR3173A, PR3173B = PR3173A+50 };
61 // PR2753
62 void foo(void) {
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}}
67 typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
70 enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
71 NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
74 /// PR3688
75 struct s1 {
76 enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
79 enum e1 { YES, NO };
81 static enum e1 badfunc(struct s1 *q) {
82 return q->bar();
86 // Make sure we don't a.k.a. anonymous enums.
87 typedef enum {
88 an_enumerator = 20
89 } an_enum;
90 char * s = (an_enum) an_enumerator; // expected-error {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}}
92 // PR4515
93 enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
94 int CheckPR4515[PR4515b==0?1:-1];
96 // PR7911
97 extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward references to 'enum' types}}
98 void PR7911F(void) {
99 switch (PR7911V) // expected-error {{statement requires expression of integer type}}
103 char test5[__has_feature(enumerator_attributes) ? 1 : -1];
105 // PR8694
106 void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}}
110 void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
111 // expected-warning {{ISO C forbids forward references to 'enum' types}}
113 PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}
116 typedef enum { NegativeShort = (short)-1 } NegativeShortEnum;
117 int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
119 // PR24610
120 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
121 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
123 // PR28903
124 // In C it is valid to define tags inside enums.
125 struct PR28903 {
126 enum {
127 PR28903_A = (enum {
128 PR28903_B,
129 PR28903_C = PR28903_B
132 int makeStructNonEmpty;
135 static int EnumRedecl; // expected-note 2 {{previous definition is here}}
136 struct S {
137 enum {
138 EnumRedecl = 4 // expected-error {{redefinition of 'EnumRedecl'}}
139 } e;
142 union U {
143 enum {
144 EnumRedecl = 5 // expected-error {{redefinition of 'EnumRedecl'}}
145 } e;
148 enum PR15071 {
149 PR15071_One // expected-note {{previous definition is here}}
152 struct EnumRedeclStruct {
153 enum {
154 PR15071_One // expected-error {{redefinition of enumerator 'PR15071_One'}}
155 } e;
158 enum struct GH42372_1 { // expected-error {{expected identifier or '{'}}
162 // Because class is not a keyword in C, this looks like a forward declaration.
163 // expected-error@+4 {{expected ';' after top level declarator}}
164 // expected-error@+3 {{tentative definition has type 'enum class' that is never completed}}
165 // expected-warning@+2 {{ISO C forbids forward references to 'enum' types}}
166 // expected-note@+1 {{forward declaration of 'enum class'}}
167 enum class GH42372_2 {