Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | 93afb0d | 2008-12-12 07:27:10 +0000 | [diff] [blame] | 3 | enum E { |
| 4 | Val1, |
| 5 | Val2 |
| 6 | }; |
| 7 | |
| 8 | int& enumerator_type(int); |
| 9 | float& enumerator_type(E); |
| 10 | |
| 11 | void f() { |
| 12 | E e = Val1; |
| 13 | float& fr = enumerator_type(Val2); |
| 14 | } |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 15 | |
| 16 | // <rdar://problem/6502934> |
| 17 | typedef enum Foo { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 18 | A = 0, |
| 19 | B = 1 |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 20 | } Foo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 21 | |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 22 | void bar() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 23 | Foo myvar = A; |
| 24 | myvar = B; |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 25 | } |
Douglas Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 26 | |
| 27 | /// PR3688 |
| 28 | struct s1 { |
John McCall | 5023437 | 2009-12-04 00:07:04 +0000 | [diff] [blame] | 29 | enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}} |
Douglas Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | enum e1 { YES, NO }; |
| 33 | |
| 34 | static enum e1 badfunc(struct s1 *q) { |
John McCall | 5023437 | 2009-12-04 00:07:04 +0000 | [diff] [blame] | 35 | return q->bar(); |
Douglas Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}} |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 39 | |
| 40 | namespace test1 { |
| 41 | template <class A, class B> struct is_same { static const int value = -1; }; |
| 42 | template <class A> struct is_same<A,A> { static const int value = 1; }; |
| 43 | |
| 44 | enum enum0 { v0 }; |
| 45 | int test0[is_same<typeof(+v0), int>::value]; |
| 46 | |
| 47 | enum enum1 { v1 = __INT_MAX__ }; |
| 48 | int test1[is_same<typeof(+v1), int>::value]; |
| 49 | |
| 50 | enum enum2 { v2 = __INT_MAX__ * 2U }; |
| 51 | int test2[is_same<typeof(+v2), unsigned int>::value]; |
| 52 | |
| 53 | // This kindof assumes that 'int' is smaller than 'long long'. |
| 54 | #if defined(__LP64__) |
| 55 | enum enum3 { v3 = __LONG_LONG_MAX__ }; |
| 56 | int test3[is_same<typeof(+v3), long>::value]; |
| 57 | |
| 58 | enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL }; |
| 59 | int test4[is_same<typeof(+v4), unsigned long>::value]; |
| 60 | #else |
| 61 | enum enum3 { v3 = __LONG_LONG_MAX__ }; |
| 62 | int test3[is_same<typeof(+v3), long long>::value]; |
| 63 | |
| 64 | enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL }; |
| 65 | int test4[is_same<typeof(+v4), unsigned long long>::value]; |
| 66 | #endif |
| 67 | } |