1 // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s
2 // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++11 -verify -triple x86_64-apple-darwin %s
3 enum E { // expected-note{{previous definition is here}}
4   Val1,
5   Val2
6 };
7 
8 enum E; // expected-warning{{redeclaration of already-defined enum 'E' is a GNU extension}}
9 
10 int& enumerator_type(int);
11 float& enumerator_type(E);
12 
f()13 void f() {
14   E e = Val1;
15   float& fr = enumerator_type(Val2);
16 }
17 
18 // <rdar://problem/6502934>
19 typedef enum Foo {
20   A = 0,
21   B = 1
22 } Foo;
23 
bar()24 void bar() {
25   Foo myvar = A;
26   myvar = B;
27 }
28 
29 /// PR3688
30 struct s1 {
31   enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
32 };
33 
34 enum e1 { YES, NO };
35 
badfunc(struct s1 * q)36 static enum e1 badfunc(struct s1 *q) {
37   return q->bar();
38 }
39 
40 enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
41 
42 namespace test1 {
43   template <class A, class B> struct is_same { static const int value = -1; };
44   template <class A> struct is_same<A,A> { static const int value = 1; };
45 
46   enum enum0 { v0 };
47   int test0[is_same<__typeof(+v0), int>::value];
48 
49   enum enum1 { v1 = __INT_MAX__ };
50   int test1[is_same<__typeof(+v1), int>::value];
51 
52   enum enum2 { v2 = __INT_MAX__ * 2U };
53   int test2[is_same<__typeof(+v2), unsigned int>::value];
54 
55   enum enum3 { v3 = __LONG_MAX__ };
56   int test3[is_same<__typeof(+v3), long>::value];
57 
58   enum enum4 { v4 = __LONG_MAX__ * 2UL };
59   int test4[is_same<__typeof(+v4), unsigned long>::value];
60 }
61 
62 // PR6061
63 namespace PR6061 {
64   struct A { enum { id }; };
65   struct B { enum { id }; };
66 
67   struct C : public A, public B
68   {
69     enum { id };
70   };
71 }
72 
73 namespace Conditional {
x(const enum a x)74   enum a { A }; a x(const enum a x) { return 1?x:A; }
75 }
76 
77 namespace PR7051 {
78   enum E { e0 };
f()79   void f() {
80     E e;
81     e = 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}}
82     e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}}
83   }
84 }
85 
86 // PR7466
87 enum { }; // expected-warning{{declaration does not declare anything}}
88 typedef enum { }; // expected-warning{{typedef requires a name}}
89 
90 // PR7921
91 enum PR7921E { // expected-note {{not complete until the closing '}'}}
92     PR7921V = (PR7921E)(123) // expected-error {{'PR7921E' is an incomplete type}}
93 };
94 
PR8089()95 void PR8089() {
96   enum E; // expected-error{{ISO C++ forbids forward references to 'enum' types}} expected-note {{forward declaration}}
97   int a = (E)3; // expected-error {{'E' is an incomplete type}}
98 }
99 
100 // This is accepted as a GNU extension. In C++98, there was no provision for
101 // expressions with UB to be non-constant.
102 enum { overflow = 123456 * 234567 };
103 #if __cplusplus >= 201103L
104 // expected-warning@-2 {{not an integral constant expression}}
105 // expected-note@-3 {{value 28958703552 is outside the range of representable values}}
106 #else
107 // expected-warning@-5 {{overflow in expression; result is -1106067520 with type 'int'}}
108 #endif
109 
110 // FIXME: This is not consistent with the above case.
111 enum NoFold : int { overflow2 = 123456 * 234567 };
112 #if __cplusplus >= 201103L
113 // expected-error@-2 {{enumerator value is not a constant expression}}
114 // expected-note@-3 {{value 28958703552 is outside the range of representable values}}
115 #else
116 // expected-warning@-5 {{overflow in expression; result is -1106067520 with type 'int'}}
117 // expected-warning@-6 {{extension}}
118 #endif
119 
120 // PR28903
121 struct PR28903 {
122   enum {
123     PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at {{.*}})' cannot be defined in an enumeration}}
124       PR28903_B,
125       PR28903_C = PR28903_B
126     })
127   };
128 };
129