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
3enum E { // expected-note{{previous definition is here}}
4  Val1,
5  Val2
6};
7
8enum E; // expected-warning{{redeclaration of already-defined enum 'E' is a GNU extension}}
9
10int& enumerator_type(int);
11float& enumerator_type(E);
12
13void f() {
14  E e = Val1;
15  float& fr = enumerator_type(Val2);
16}
17
18// <rdar://problem/6502934>
19typedef enum Foo {
20  A = 0,
21  B = 1
22} Foo;
23
24void bar() {
25  Foo myvar = A;
26  myvar = B;
27}
28
29/// PR3688
30struct s1 {
31  enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
32};
33
34enum e1 { YES, NO };
35
36static enum e1 badfunc(struct s1 *q) {
37  return q->bar();
38}
39
40enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
41
42namespace 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
63namespace 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
73namespace Conditional {
74  enum a { A }; a x(const enum a x) { return 1?x:A; }
75}
76
77namespace PR7051 {
78  enum E { e0 };
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
87enum { }; // expected-warning{{declaration does not declare anything}}
88typedef enum { }; // expected-warning{{typedef requires a name}}
89
90// PR7921
91enum PR7921E {
92    PR7921V = (PR7921E)(123)
93#if __cplusplus < 201103L
94// expected-error@-2 {{expression is not an integral constant expression}}
95#else
96// expected-error@-4 {{must have integral or unscoped enumeration type}}
97// FIXME: The above diagnostic isn't very good; we should instead complain about the type being incomplete.
98#endif
99};
100
101void PR8089() {
102  enum E; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
103  int a = (E)3; // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'E'}}
104}
105
106// This is accepted as a GNU extension. In C++98, there was no provision for
107// expressions with UB to be non-constant.
108enum { overflow = 123456 * 234567 };
109#if __cplusplus >= 201103L
110// expected-warning@-2 {{not an integral constant expression}}
111// expected-note@-3 {{value 28958703552 is outside the range of representable values}}
112#endif
113