blob: dbc250abc3b64fdfcb92f273de9119f64ece312a [file] [log] [blame]
Chris Lattner3b427b32007-10-11 00:18:28 +00001// RUN: clang %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
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
Douglas Gregor275a3692009-03-10 23:43:53 +000024enum 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'}}
Steve Naroff67c49e82008-01-16 23:54:22 +000027
28int test2(int i)
29{
Douglas Gregora03aca82009-03-10 21:58:27 +000030 ve + i; // expected-error{{invalid operands to binary expression}}
Steve Naroff67c49e82008-01-16 23:54:22 +000031}
Chris Lattner14943b92008-07-03 03:30:58 +000032
33// PR2020
Chris Lattner5f4a6822008-11-23 23:12:31 +000034union u0; // expected-note {{previous use is here}}
35enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
Chris Lattner14943b92008-07-03 03:30:58 +000036
Chris Lattner834a72a2008-07-25 23:18:17 +000037
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 ;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000044 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
Chris Lattner834a72a2008-07-25 23:18:17 +000045
46 for (; ;ve2)
47 ;
48 (void)ve2;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000049 ve2; // expected-warning {{expression result unused}}
Chris Lattner834a72a2008-07-25 23:18:17 +000050}
51
Chris Lattnerbe899092008-07-26 19:15:11 +000052// PR2416
53enum someenum {}; // expected-warning {{use of empty enum extension}}
54
Daniel Dunbar45e52e12008-08-07 16:22:45 +000055// <rdar://problem/6093889>
Chris Lattner5f4a6822008-11-23 23:12:31 +000056enum e0 { // expected-note {{previous definition is here}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000057 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
Daniel Dunbar45e52e12008-08-07 16:22:45 +000058};
Eli Friedmane9a0f432008-12-08 02:21:03 +000059
60// PR3173
61enum { PR3173A, PR3173B = PR3173A+50 };
Douglas Gregor7df7b6b2008-12-15 16:32:14 +000062
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}
Douglas Gregor8158f692009-01-17 02:55:50 +000068
69// <rdar://problem/6503878>
70typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000071
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};
Douglas Gregor80711a22009-03-06 18:34:03 +000076
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}