Chris Lattner | 3b427b3 | 2007-10-11 00:18:28 +0000 | [diff] [blame] | 1 | // RUN: clang %s -fsyntax-only -verify -pedantic |
Chris Lattner | ac60968 | 2007-08-28 06:15:15 +0000 | [diff] [blame] | 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 | }; |
| 14 | |
| 15 | // minll maxull |
| 16 | enum 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'}} |
| 18 | z = 9223372036854775808ULL }; // expected-warning {{ISO C restricts enumerator values to range of 'int'}} |
| 19 | |
| 20 | int test() { |
| 21 | return sizeof(enum e) ; |
| 22 | } |
| 23 | |
Douglas Gregor | 275a369 | 2009-03-10 23:43:53 +0000 | [diff] [blame] | 24 | enum 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 Naroff | 67c49e8 | 2008-01-16 23:54:22 +0000 | [diff] [blame] | 27 | |
| 28 | int test2(int i) |
| 29 | { |
Douglas Gregor | a03aca8 | 2009-03-10 21:58:27 +0000 | [diff] [blame] | 30 | ve + i; // expected-error{{invalid operands to binary expression}} |
Steve Naroff | 67c49e8 | 2008-01-16 23:54:22 +0000 | [diff] [blame] | 31 | } |
Chris Lattner | 14943b9 | 2008-07-03 03:30:58 +0000 | [diff] [blame] | 32 | |
| 33 | // PR2020 |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 34 | union u0; // expected-note {{previous use is here}} |
| 35 | enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}} |
Chris Lattner | 14943b9 | 2008-07-03 03:30:58 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 37 | |
| 38 | // rdar://6095136 |
| 39 | extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}} |
| 40 | |
| 41 | void test4() { |
| 42 | for (; ve2;) // expected-error {{statement requires expression of scalar type}} |
| 43 | ; |
Chris Lattner | d67cd9e | 2008-07-25 23:41:08 +0000 | [diff] [blame] | 44 | (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}} |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 45 | |
| 46 | for (; ;ve2) |
| 47 | ; |
| 48 | (void)ve2; |
Chris Lattner | d67cd9e | 2008-07-25 23:41:08 +0000 | [diff] [blame] | 49 | ve2; // expected-warning {{expression result unused}} |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Chris Lattner | be89909 | 2008-07-26 19:15:11 +0000 | [diff] [blame] | 52 | // PR2416 |
| 53 | enum someenum {}; // expected-warning {{use of empty enum extension}} |
| 54 | |
Daniel Dunbar | 45e52e1 | 2008-08-07 16:22:45 +0000 | [diff] [blame] | 55 | // <rdar://problem/6093889> |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 56 | enum e0 { // expected-note {{previous definition is here}} |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 57 | E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}} |
Daniel Dunbar | 45e52e1 | 2008-08-07 16:22:45 +0000 | [diff] [blame] | 58 | }; |
Eli Friedman | e9a0f43 | 2008-12-08 02:21:03 +0000 | [diff] [blame] | 59 | |
| 60 | // PR3173 |
| 61 | enum { PR3173A, PR3173B = PR3173A+50 }; |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 62 | |
| 63 | // PR2753 |
| 64 | void 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 Gregor | 8158f69 | 2009-01-17 02:55:50 +0000 | [diff] [blame] | 68 | |
| 69 | // <rdar://problem/6503878> |
| 70 | typedef enum { X = 0 }; // expected-warning{{typedef requires a name}} |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 71 | |
| 72 | |
| 73 | enum 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 Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 76 | |
| 77 | /// PR3688 |
| 78 | struct s1 { |
| 79 | enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}} |
| 80 | }; |
| 81 | |
| 82 | enum e1 { YES, NO }; |
| 83 | |
| 84 | static enum e1 badfunc(struct s1 *q) { |
| 85 | return q->bar(); |
| 86 | } |