blob: 37c9a1e7cf9245c9ab7920b4f8a470611432d9b5 [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 Gregora03aca82009-03-10 21:58:27 +000024enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}}
Steve Naroff67c49e82008-01-16 23:54:22 +000025
26int test2(int i)
27{
Douglas Gregora03aca82009-03-10 21:58:27 +000028 ve + i; // expected-error{{invalid operands to binary expression}}
Steve Naroff67c49e82008-01-16 23:54:22 +000029}
Chris Lattner14943b92008-07-03 03:30:58 +000030
31// PR2020
Chris Lattner5f4a6822008-11-23 23:12:31 +000032union u0; // expected-note {{previous use is here}}
33enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
Chris Lattner14943b92008-07-03 03:30:58 +000034
Chris Lattner834a72a2008-07-25 23:18:17 +000035
36// rdar://6095136
37extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
38
39void test4() {
40 for (; ve2;) // expected-error {{statement requires expression of scalar type}}
41 ;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000042 (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
Chris Lattner834a72a2008-07-25 23:18:17 +000043
44 for (; ;ve2)
45 ;
46 (void)ve2;
Chris Lattnerd67cd9e2008-07-25 23:41:08 +000047 ve2; // expected-warning {{expression result unused}}
Chris Lattner834a72a2008-07-25 23:18:17 +000048}
49
Chris Lattnerbe899092008-07-26 19:15:11 +000050// PR2416
51enum someenum {}; // expected-warning {{use of empty enum extension}}
52
Daniel Dunbar45e52e12008-08-07 16:22:45 +000053// <rdar://problem/6093889>
Chris Lattner5f4a6822008-11-23 23:12:31 +000054enum e0 { // expected-note {{previous definition is here}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000055 E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
Daniel Dunbar45e52e12008-08-07 16:22:45 +000056};
Eli Friedmane9a0f432008-12-08 02:21:03 +000057
58// PR3173
59enum { PR3173A, PR3173B = PR3173A+50 };
Douglas Gregor7df7b6b2008-12-15 16:32:14 +000060
61// PR2753
62void foo() {
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}}
65}
Douglas Gregor8158f692009-01-17 02:55:50 +000066
67// <rdar://problem/6503878>
68typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000069
70
71enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
72 NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
73};
Douglas Gregor80711a22009-03-06 18:34:03 +000074
75/// PR3688
76struct s1 {
77 enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
78};
79
80enum e1 { YES, NO };
81
82static enum e1 badfunc(struct s1 *q) {
83 return q->bar();
84}