blob: 370e1c34d29c8e736b58960e6f7da04b92b4e6ef [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
Douglas Gregorf3a7b7c2010-06-22 14:26:35 +00002enum E { // expected-note{{previous definition is here}}
Douglas Gregor93afb0d2008-12-12 07:27:10 +00003 Val1,
4 Val2
5};
6
Douglas Gregorf3a7b7c2010-06-22 14:26:35 +00007enum E; // expected-warning{{redeclaration of already-defined enum 'E' is a GNU extension}}
8
Douglas Gregor93afb0d2008-12-12 07:27:10 +00009int& enumerator_type(int);
10float& enumerator_type(E);
11
12void f() {
13 E e = Val1;
14 float& fr = enumerator_type(Val2);
15}
Douglas Gregor66b947f2009-01-16 19:38:23 +000016
17// <rdar://problem/6502934>
18typedef enum Foo {
Mike Stump1eb44332009-09-09 15:08:12 +000019 A = 0,
20 B = 1
Douglas Gregor66b947f2009-01-16 19:38:23 +000021} Foo;
Mike Stump1eb44332009-09-09 15:08:12 +000022
Douglas Gregor66b947f2009-01-16 19:38:23 +000023void bar() {
Mike Stump1eb44332009-09-09 15:08:12 +000024 Foo myvar = A;
25 myvar = B;
Douglas Gregor66b947f2009-01-16 19:38:23 +000026}
Douglas Gregor80711a22009-03-06 18:34:03 +000027
28/// PR3688
29struct s1 {
John McCall50234372009-12-04 00:07:04 +000030 enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
Douglas Gregor80711a22009-03-06 18:34:03 +000031};
32
33enum e1 { YES, NO };
34
35static enum e1 badfunc(struct s1 *q) {
John McCall50234372009-12-04 00:07:04 +000036 return q->bar();
Douglas Gregor80711a22009-03-06 18:34:03 +000037}
38
39enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
John McCall842aef82009-12-09 09:09:27 +000040
41namespace test1 {
42 template <class A, class B> struct is_same { static const int value = -1; };
43 template <class A> struct is_same<A,A> { static const int value = 1; };
44
45 enum enum0 { v0 };
Eli Friedman2aaad632009-12-16 20:30:08 +000046 int test0[is_same<__typeof(+v0), int>::value];
John McCall842aef82009-12-09 09:09:27 +000047
48 enum enum1 { v1 = __INT_MAX__ };
Eli Friedman2aaad632009-12-16 20:30:08 +000049 int test1[is_same<__typeof(+v1), int>::value];
John McCall842aef82009-12-09 09:09:27 +000050
51 enum enum2 { v2 = __INT_MAX__ * 2U };
Eli Friedman2aaad632009-12-16 20:30:08 +000052 int test2[is_same<__typeof(+v2), unsigned int>::value];
John McCall842aef82009-12-09 09:09:27 +000053
Eli Friedman2aaad632009-12-16 20:30:08 +000054 enum enum3 { v3 = __LONG_MAX__ };
55 int test3[is_same<__typeof(+v3), long>::value];
John McCall842aef82009-12-09 09:09:27 +000056
Eli Friedman2aaad632009-12-16 20:30:08 +000057 enum enum4 { v4 = __LONG_MAX__ * 2UL };
58 int test4[is_same<__typeof(+v4), unsigned long>::value];
John McCall842aef82009-12-09 09:09:27 +000059}
Douglas Gregore39fe722010-01-19 06:06:57 +000060
61// PR6061
62namespace PR6061 {
63 struct A { enum { id }; };
64 struct B { enum { id }; };
65
66 struct C : public A, public B
67 {
68 enum { id };
69 };
70}
Douglas Gregora873dfc2010-02-03 00:27:59 +000071
72namespace Conditional {
73 enum a { A }; a x(const enum a x) { return 1?x:A; }
74}
Douglas Gregor88623ad2010-05-23 21:53:47 +000075
76namespace PR7051 {
77 enum E { e0 };
78 void f() {
79 E e;
80 e = 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}}
81 e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}}
82 }
83}
Douglas Gregora131d0f2010-07-13 06:24:26 +000084
85// PR7466
86enum { }; // expected-warning{{declaration does not declare anything}}
87typedef enum { }; // expected-warning{{typedef requires a name}}
Eli Friedman34fd6282010-08-19 04:39:37 +000088
89// PR7921
90enum PR7921E {
Richard Smith244ee7b2012-01-15 03:51:30 +000091 PR7921V = (PR7921E)(123) // expected-error {{expression is not an integral constant expression}}
Eli Friedman34fd6282010-08-19 04:39:37 +000092};
Douglas Gregor5dde1602010-09-12 03:38:25 +000093
94void PR8089() {
95 enum E; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
96 int a = (E)3; // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'E'}}
97}