1 /* { dg-do compile } */
2 /* { dg-options "-Wc++-compat" } */
3 enum E1 { A, B, C };
4 enum E2 { D, E, F };
5
6 enum E1 v1a = A;
7 enum E1 v1b = D; /* { dg-warning "invalid in C\[+\]\[+\]" } */
8 enum E1 v1c = 0; /* { dg-warning "invalid in C\[+\]\[+\]" } */
9 enum E1 v1d = (enum E1) 0;
10 enum E1 v1e = (enum E2) 0; /* { dg-warning "invalid in C\[+\]\[+\]" } */
11
12 enum E2 v2a;
13
14 enum E1 a1[] =
15 {
16 A,
17 D, /* { dg-warning "invalid in C\[+\]\[+\]" } */
18 0, /* { dg-warning "invalid in C\[+\]\[+\]" } */
19 (enum E1) 0,
20 (enum E2) 0, /* { dg-warning "invalid in C\[+\]\[+\]" } */
21 A
22 };
23
24 struct s1
25 {
26 enum E1 e1;
27 };
28
29 struct s1 a2[] =
30 {
31 { A },
32 { D }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
33 { 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
34 { (enum E1) 0 },
35 { (enum E2) 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
36 { A }
37 };
38
39 struct s1 a3[] =
40 {
41 [ 5 ] = { .e1 = A },
42 [ 4 ] = { .e1 = D }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
43 [ 3 ] = { .e1 = 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
44 [ 2 ] = { .e1 = (enum E1) 0 },
45 [ 1 ] = { .e1 = (enum E2) 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
46 [ 0 ] = { .e1 = A }
47 };
48
49 struct s2
50 {
51 enum E1 e1 : 3;
52 };
53
54 struct s2 a4[] =
55 {
56 { A },
57 { D }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
58 { 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
59 { (enum E1) 0 },
60 { (enum E2) 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
61 { A }
62 };
63
64 struct s2 a5[] =
65 {
66 [ 5 ] = { .e1 = A },
67 [ 4 ] = { .e1 = D }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
68 [ 3 ] = { .e1 = 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
69 [ 2 ] = { .e1 = (enum E1) 0 },
70 [ 1 ] = { .e1 = (enum E2) 0 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
71 [ 0 ] = { .e1 = A }
72 };
73
74 void
f(enum E1 e1,enum E2 e2,struct s1 vs1,struct s1 * vp1)75 f(enum E1 e1, enum E2 e2, struct s1 vs1, struct s1 *vp1)
76 {
77 enum E1 va1[] = {
78 e1,
79 e2, /* { dg-warning "invalid in C\[+\]\[+\]" } */
80 v1a,
81 v2a, /* { dg-warning "invalid in C\[+\]\[+\]" } */
82 vs1.e1,
83 vp1->e1,
84 e1 ? e1 : e1,
85 (0, e1)
86 };
87
88 struct s1 va2[] = {
89 { e1 },
90 { e2 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
91 { v1a },
92 { v2a }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
93 { vs1.e1 },
94 { vp1->e1 },
95 { e1 ? e1 : e1 },
96 { (0, e1) }
97 };
98
99 struct s2 va3[] = {
100 { e1 },
101 { e2 }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
102 { v1a },
103 { v2a }, /* { dg-warning "invalid in C\[+\]\[+\]" } */
104 { vs1.e1 },
105 { vp1->e1 },
106 { e1 ? e1 : e1 },
107 { (0, e1) }
108 };
109 }
110
111 /* Match all extra informative notes. */
112 /* { dg-warning "near initialization for" "expected" { target *-*-* } 0 } */
113