blob: f1b02f5d4c6dbb98baf8473e2fa126b95843fc9d [file] [log] [blame]
Eli Friedman5f7157e2009-12-16 20:47:15 +00001// RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s
John McCall842aef82009-12-09 09:09:27 +00002
Douglas Gregor93afb0d2008-12-12 07:27:10 +00003enum E {
4 Val1,
5 Val2
6};
7
8int& enumerator_type(int);
9float& enumerator_type(E);
10
11void f() {
12 E e = Val1;
13 float& fr = enumerator_type(Val2);
14}
Douglas Gregor66b947f2009-01-16 19:38:23 +000015
16// <rdar://problem/6502934>
17typedef enum Foo {
Mike Stump1eb44332009-09-09 15:08:12 +000018 A = 0,
19 B = 1
Douglas Gregor66b947f2009-01-16 19:38:23 +000020} Foo;
Mike Stump1eb44332009-09-09 15:08:12 +000021
Douglas Gregor66b947f2009-01-16 19:38:23 +000022void bar() {
Mike Stump1eb44332009-09-09 15:08:12 +000023 Foo myvar = A;
24 myvar = B;
Douglas Gregor66b947f2009-01-16 19:38:23 +000025}
Douglas Gregor80711a22009-03-06 18:34:03 +000026
27/// PR3688
28struct s1 {
John McCall50234372009-12-04 00:07:04 +000029 enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
Douglas Gregor80711a22009-03-06 18:34:03 +000030};
31
32enum e1 { YES, NO };
33
34static enum e1 badfunc(struct s1 *q) {
John McCall50234372009-12-04 00:07:04 +000035 return q->bar();
Douglas Gregor80711a22009-03-06 18:34:03 +000036}
37
38enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
John McCall842aef82009-12-09 09:09:27 +000039
40namespace 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 };
Eli Friedman2aaad632009-12-16 20:30:08 +000045 int test0[is_same<__typeof(+v0), int>::value];
John McCall842aef82009-12-09 09:09:27 +000046
47 enum enum1 { v1 = __INT_MAX__ };
Eli Friedman2aaad632009-12-16 20:30:08 +000048 int test1[is_same<__typeof(+v1), int>::value];
John McCall842aef82009-12-09 09:09:27 +000049
50 enum enum2 { v2 = __INT_MAX__ * 2U };
Eli Friedman2aaad632009-12-16 20:30:08 +000051 int test2[is_same<__typeof(+v2), unsigned int>::value];
John McCall842aef82009-12-09 09:09:27 +000052
Eli Friedman2aaad632009-12-16 20:30:08 +000053 enum enum3 { v3 = __LONG_MAX__ };
54 int test3[is_same<__typeof(+v3), long>::value];
John McCall842aef82009-12-09 09:09:27 +000055
Eli Friedman2aaad632009-12-16 20:30:08 +000056 enum enum4 { v4 = __LONG_MAX__ * 2UL };
57 int test4[is_same<__typeof(+v4), unsigned long>::value];
John McCall842aef82009-12-09 09:09:27 +000058}