| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
enum class Color1 { |
| 3 |
Red, |
| 4 |
Green, |
| 5 |
Blue |
| 6 |
}; |
| 7 |
|
| 8 |
enum struct Color2 { |
| 9 |
Red, // { dg-message "previously declared here" } |
| 10 |
Orange, |
| 11 |
Yellow, |
| 12 |
Green, |
| 13 |
Blue, |
| 14 |
Indigo = Green + 2, |
| 15 |
Violet, |
| 16 |
Red // { dg-error "redeclaration" } |
| 17 |
}; |
| 18 |
|
| 19 |
enum Color { |
| 20 |
Red, Green, Blue |
| 21 |
}; |
| 22 |
|
| 23 |
enum class Color3 { |
| 24 |
Red |
| 25 |
}; |
| 26 |
|
| 27 |
enum Color color; |
| 28 |
enum Color3 color3; |
| 29 |
|
| 30 |
void f(int); |
| 31 |
void f2(Color3); |
| 32 |
|
| 33 |
void g() |
| 34 |
{ |
| 35 |
int i = 0; |
| 36 |
f(color); // okay: unscoped enum |
| 37 |
f(color3); // { dg-error "cannot convert" } |
| 38 |
f2(color); // { dg-error "cannot convert" } |
| 39 |
f2(color3); |
| 40 |
f2(i); // { dg-error "cannot convert" } |
| 41 |
i = color3; // { dg-error "cannot convert" } |
| 42 |
color3 = i; // { dg-error "cannot convert" } |
| 43 |
f(static_cast<int>(color3)); // okay |
| 44 |
|
| 45 |
int a[5]; |
| 46 |
a[color3]; // { dg-error "array subscript is not an integer" } |
| 47 |
|
| 48 |
bool b = color3; // { dg-error "cannot convert" } |
| 49 |
} |
| 50 |
|
| 51 |
void h() |
| 52 |
{ |
| 53 |
Color1 c1 = Color1::Red; |
| 54 |
Color2 c2 = Color1::Red; // { dg-error "cannot convert" } |
| 55 |
c2 = Color1::Red; // { dg-error "cannot convert" } |
| 56 |
|
| 57 |
c2 = Color2::Red; |
| 58 |
int c3 = Color::Red; |
| 59 |
} |
| 60 |
|
| 61 |
template<typename T, T value> |
| 62 |
struct constant { }; |
| 63 |
|
| 64 |
template<typename T> |
| 65 |
int& sfinae(constant<T, T::Green>*); |
| 66 |
|
| 67 |
float& sfinae(void*); |
| 68 |
|
| 69 |
void sfinae_test() |
| 70 |
{ |
| 71 |
int& test1 = sfinae((constant<Color1, Color1::Green>*)0); |
| 72 |
int& test2 = sfinae((constant<Color2, Color2::Green>*)0); |
| 73 |
float& test3 = sfinae((constant<Color1, Color1::Red>*)0); |
| 74 |
int& test4 = sfinae((constant<Color, Green>*)0); |
| 75 |
float& test5 = sfinae((constant<Color, Red>*)0); |
| 76 |
} |