blob: dc4a506dda21ca672c9c27a7566cc13b925b1b4a [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001// RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s
2
3enum 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}
15
16// <rdar://problem/6502934>
17typedef enum Foo {
18 A = 0,
19 B = 1
20} Foo;
21
22void bar() {
23 Foo myvar = A;
24 myvar = B;
25}
26
27/// PR3688
28struct s1 {
29 enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
30};
31
32enum e1 { YES, NO };
33
34static enum e1 badfunc(struct s1 *q) {
35 return q->bar();
36}
37
38enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
39
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 };
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 enum enum3 { v3 = __LONG_MAX__ };
54 int test3[is_same<__typeof(+v3), long>::value];
55
56 enum enum4 { v4 = __LONG_MAX__ * 2UL };
57 int test4[is_same<__typeof(+v4), unsigned long>::value];
58}
59
60// PR6061
61namespace PR6061 {
62 struct A { enum { id }; };
63 struct B { enum { id }; };
64
65 struct C : public A, public B
66 {
67 enum { id };
68 };
69}
70
71namespace Conditional {
72 enum a { A }; a x(const enum a x) { return 1?x:A; }
73}