Eli Friedman | 5f7157e | 2009-12-16 20:47:15 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s |
Douglas Gregor | 93afb0d | 2008-12-12 07:27:10 +0000 | [diff] [blame] | 2 | enum E { |
| 3 | Val1, |
| 4 | Val2 |
| 5 | }; |
| 6 | |
| 7 | int& enumerator_type(int); |
| 8 | float& enumerator_type(E); |
| 9 | |
| 10 | void f() { |
| 11 | E e = Val1; |
| 12 | float& fr = enumerator_type(Val2); |
| 13 | } |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 14 | |
| 15 | // <rdar://problem/6502934> |
| 16 | typedef enum Foo { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 17 | A = 0, |
| 18 | B = 1 |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 19 | } Foo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 20 | |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 21 | void bar() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 22 | Foo myvar = A; |
| 23 | myvar = B; |
Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 24 | } |
Douglas Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 25 | |
| 26 | /// PR3688 |
| 27 | struct s1 { |
John McCall | 5023437 | 2009-12-04 00:07:04 +0000 | [diff] [blame] | 28 | 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] | 29 | }; |
| 30 | |
| 31 | enum e1 { YES, NO }; |
| 32 | |
| 33 | static enum e1 badfunc(struct s1 *q) { |
John McCall | 5023437 | 2009-12-04 00:07:04 +0000 | [diff] [blame] | 34 | return q->bar(); |
Douglas Gregor | 80711a2 | 2009-03-06 18:34:03 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}} |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 38 | |
| 39 | namespace test1 { |
| 40 | template <class A, class B> struct is_same { static const int value = -1; }; |
| 41 | template <class A> struct is_same<A,A> { static const int value = 1; }; |
| 42 | |
| 43 | enum enum0 { v0 }; |
Eli Friedman | 2aaad63 | 2009-12-16 20:30:08 +0000 | [diff] [blame] | 44 | int test0[is_same<__typeof(+v0), int>::value]; |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 45 | |
| 46 | enum enum1 { v1 = __INT_MAX__ }; |
Eli Friedman | 2aaad63 | 2009-12-16 20:30:08 +0000 | [diff] [blame] | 47 | int test1[is_same<__typeof(+v1), int>::value]; |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 48 | |
| 49 | enum enum2 { v2 = __INT_MAX__ * 2U }; |
Eli Friedman | 2aaad63 | 2009-12-16 20:30:08 +0000 | [diff] [blame] | 50 | int test2[is_same<__typeof(+v2), unsigned int>::value]; |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 51 | |
Eli Friedman | 2aaad63 | 2009-12-16 20:30:08 +0000 | [diff] [blame] | 52 | enum enum3 { v3 = __LONG_MAX__ }; |
| 53 | int test3[is_same<__typeof(+v3), long>::value]; |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 54 | |
Eli Friedman | 2aaad63 | 2009-12-16 20:30:08 +0000 | [diff] [blame] | 55 | enum enum4 { v4 = __LONG_MAX__ * 2UL }; |
| 56 | int test4[is_same<__typeof(+v4), unsigned long>::value]; |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 57 | } |
Douglas Gregor | e39fe72 | 2010-01-19 06:06:57 +0000 | [diff] [blame] | 58 | |
| 59 | // PR6061 |
| 60 | namespace PR6061 { |
| 61 | struct A { enum { id }; }; |
| 62 | struct B { enum { id }; }; |
| 63 | |
| 64 | struct C : public A, public B |
| 65 | { |
| 66 | enum { id }; |
| 67 | }; |
| 68 | } |
Douglas Gregor | a873dfc | 2010-02-03 00:27:59 +0000 | [diff] [blame] | 69 | |
| 70 | namespace Conditional { |
| 71 | enum a { A }; a x(const enum a x) { return 1?x:A; } |
| 72 | } |
Douglas Gregor | 88623ad | 2010-05-23 21:53:47 +0000 | [diff] [blame^] | 73 | |
| 74 | namespace PR7051 { |
| 75 | enum E { e0 }; |
| 76 | void f() { |
| 77 | E e; |
| 78 | e = 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}} |
| 79 | e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}} |
| 80 | } |
| 81 | } |