blob: ba4e56b907a72c667dc736c11005d4ff16ed3196 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
Chris Lattnerac609682007-08-28 06:15:15 +00002enum 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
Douglas Gregor19c15252010-02-17 22:40:11 +000012 f = 2147483648, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
13 i = 0xFFFF0000 // expected-warning {{too large}}
Chris Lattnerac609682007-08-28 06:15:15 +000014};
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
Douglas Gregor275a3692009-03-10 23:43:53 +000025enum 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'}}
Steve Naroff67c49e82008-01-16 23:54:22 +000028
29int test2(int i)
30{
Douglas Gregora03aca82009-03-10 21:58:27 +000031 ve + i; // expected-error{{invalid operands to binary expression}}
Steve Naroff67c49e82008-01-16 23:54:22 +000032}
Chris Lattner14943b92008-07-03 03:30:58 +000033
34// PR2020
Chris Lattner5f4a6822008-11-23 23:12:31 +000035union u0; // expected-note {{previous use is here}}
36enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
Chris Lattner14943b92008-07-03 03:30:58 +000037
Chris Lattner834a72a2008-07-25 23:18:17 +000038
39// rdar://6095136
40extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
41
42void test4() {
43 for (; ve2;) // expected-error {{statement requires expression of scalar type}}
44 ;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000045 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
Chris Lattner834a72a2008-07-25 23:18:17 +000046
Daniel Dunbar4dabe962009-08-01 06:07:15 +000047 for (; ;ve2) // expected-warning {{expression result unused}}
Chris Lattner834a72a2008-07-25 23:18:17 +000048 ;
49 (void)ve2;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000050 ve2; // expected-warning {{expression result unused}}
Chris Lattner834a72a2008-07-25 23:18:17 +000051}
52
Chris Lattnerbe899092008-07-26 19:15:11 +000053// PR2416
54enum someenum {}; // expected-warning {{use of empty enum extension}}
55
Daniel Dunbar45e52e12008-08-07 16:22:45 +000056// <rdar://problem/6093889>
Chris Lattner5f4a6822008-11-23 23:12:31 +000057enum e0 { // expected-note {{previous definition is here}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000058 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
Daniel Dunbar45e52e12008-08-07 16:22:45 +000059};
Eli Friedmane9a0f432008-12-08 02:21:03 +000060
61// PR3173
62enum { PR3173A, PR3173B = PR3173A+50 };
Douglas Gregor7df7b6b2008-12-15 16:32:14 +000063
64// PR2753
65void 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}
Douglas Gregor8158f692009-01-17 02:55:50 +000069
70// <rdar://problem/6503878>
71typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000072
73
74enum 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};
Douglas Gregor80711a22009-03-06 18:34:03 +000077
78/// PR3688
79struct s1 {
80 enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
81};
82
83enum e1 { YES, NO };
84
85static enum e1 badfunc(struct s1 *q) {
86 return q->bar();
87}
John McCall64f7e252010-01-13 22:07:44 +000088
89
90// Make sure we don't a.k.a. anonymous enums.
91typedef enum {
92 an_enumerator = 20
93} an_enum;
Douglas Gregor08a41902010-04-09 17:53:29 +000094char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}}
Douglas Gregor677e4fe2010-02-01 23:36:03 +000095
96// PR4515
97enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
98int CheckPR4515[PR4515b==0?1:-1];