Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++0x -verify -triple x86_64-apple-darwin %s |
| 2 | |
| 3 | enum class E1 { |
| 4 | Val1 = 1L |
| 5 | }; |
| 6 | |
| 7 | enum struct E2 { |
| 8 | Val1 = '\0' |
| 9 | }; |
| 10 | |
| 11 | E1 v1 = Val1; // expected-error{{undeclared identifier}} |
| 12 | E1 v2 = E1::Val1; |
| 13 | |
| 14 | static_assert(sizeof(E1) == sizeof(int), "bad size"); |
| 15 | static_assert(sizeof(E1::Val1) == sizeof(int), "bad size"); |
| 16 | static_assert(sizeof(E2) == sizeof(int), "bad size"); |
| 17 | static_assert(sizeof(E2::Val1) == sizeof(int), "bad size"); |
| 18 | |
| 19 | E1 v3 = E2::Val1; // expected-error{{cannot initialize a variable}} |
| 20 | int x1 = E1::Val1; // expected-error{{cannot initialize a variable}} |
| 21 | |
| 22 | enum E3 : char { |
| 23 | Val2 = 1 |
| 24 | }; |
| 25 | |
| 26 | E3 v4 = Val2; |
| 27 | E1 v5 = Val2; // expected-error{{cannot initialize a variable}} |
| 28 | |
| 29 | static_assert(sizeof(E3) == 1, "bad size"); |
| 30 | |
| 31 | int x2 = Val2; |
| 32 | |
| 33 | int a1[Val2]; |
| 34 | int a2[E1::Val1]; // expected-error{{size of array has non-integer type}} |
| 35 | |
| 36 | int* p1 = new int[Val2]; |
| 37 | int* p2 = new int[E1::Val1]; // FIXME Expected-error{{must have integral}} |
| 38 | |
| 39 | enum class E4 { |
| 40 | e1 = -2147483648, // ok |
| 41 | e2 = 2147483647, // ok |
| 42 | e3 = 2147483648 // expected-error{{value is not representable}} |
| 43 | }; |
| 44 | |
| 45 | enum class E5 { |
| 46 | e1 = 2147483647, // ok |
| 47 | e2 // expected-error{{2147483648 is not representable in the underlying}} |
| 48 | }; |
| 49 | |
| 50 | enum class E6 : bool { |
| 51 | e1 = false, e2 = true, |
| 52 | e3 // expected-error{{2 is not representable in the underlying}} |
| 53 | }; |
| 54 | |
| 55 | enum E7 : bool { |
| 56 | e1 = false, e2 = true, |
| 57 | e3 // expected-error{{2 is not representable in the underlying}} |
| 58 | }; |
| 59 | |
| 60 | template <class T> |
| 61 | struct X { |
| 62 | enum E : T { |
| 63 | e1, e2, |
| 64 | e3 // expected-error{{2 is not representable in the underlying}} |
| 65 | }; |
| 66 | }; |
| 67 | |
| 68 | X<bool> X2; // expected-note{{in instantiation of template}} |
| 69 | |
| 70 | enum Incomplete1; // expected-error{{C++ forbids forward references}} |
| 71 | |
| 72 | enum Complete1 : int; |
| 73 | Complete1 complete1; |
| 74 | |
| 75 | enum class Complete2; |
| 76 | Complete2 complete2; |
| 77 | |
| 78 | // All the redeclarations below are done twice on purpose. Tests that the type |
| 79 | // of the declaration isn't changed. |
| 80 | |
| 81 | enum class Redeclare2; // expected-note{{previous use is here}} expected-note{{previous use is here}} |
| 82 | enum Redeclare2; // expected-error{{previously declared as scoped}} |
| 83 | enum Redeclare2; // expected-error{{previously declared as scoped}} |
| 84 | |
| 85 | enum Redeclare3 : int; // expected-note{{previous use is here}} expected-note{{previous use is here}} |
| 86 | enum Redeclare3; // expected-error{{previously declared with fixed underlying type}} |
| 87 | enum Redeclare3; // expected-error{{previously declared with fixed underlying type}} |
| 88 | |
| 89 | enum class Redeclare5; |
| 90 | enum class Redeclare5 : int; // ok |
| 91 | |
| 92 | enum Redeclare6 : int; // expected-note{{previous use is here}} expected-note{{previous use is here}} |
| 93 | enum Redeclare6 : short; // expected-error{{redeclared with different underlying type}} |
| 94 | enum Redeclare6 : short; // expected-error{{redeclared with different underlying type}} |
| 95 | |
| 96 | enum class Redeclare7; // expected-note{{previous use is here}} expected-note{{previous use is here}} |
| 97 | enum class Redeclare7 : short; // expected-error{{redeclared with different underlying type}} |
| 98 | enum class Redeclare7 : short; // expected-error{{redeclared with different underlying type}} |
Douglas Gregor | 6cd5ae4 | 2011-02-22 02:55:24 +0000 | [diff] [blame] | 99 | |
| 100 | enum : long { |
| 101 | long_enum_val = 10000 |
| 102 | }; |
| 103 | |
| 104 | enum : long x; // expected-error{{unnamed enumeration must be a definition}} \ |
| 105 | // expected-warning{{declaration does not declare anything}} |