1 /* PR c/59855 */
2 /* { dg-do compile } */
3 /* { dg-options "-std=gnu99" } */
4 
5 typedef int vvv  __attribute__((designated_init)); /* { dg-error "only valid" } */
6 
7 union U {
8   int a;
9   double b;
10 } __attribute__((designated_init)); /* { dg-error "only valid" } */
11 
12 enum E { ONE, TWO }  __attribute__((designated_init)); /* { dg-error "only valid" } */
13 
14 struct Pok {
15   int x;
16   int y;
17 };
18 
19 struct Des {
20   int x;
21   int y;
22 } __attribute__ ((designated_init));
23 
24 struct Des d1 = { 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
25 struct Des d2 = { .x = 5, .y = 5 };
26 struct Des d3 = { .x = 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
27 
fd1(void)28 struct Des fd1 (void)
29 {
30   return (struct Des) { 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
31 }
32 
fd2(void)33 struct Des fd2 (void)
34 {
35   return (struct Des) { .x = 5, .y = 5 };
36 }
37 
fd3(void)38 struct Des fd3 (void)
39 {
40   return (struct Des) { .x = 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
41 }
42 
43 struct Wrap {
44   struct Pok p;
45   struct Des d;
46 } __attribute__ ((designated_init));
47 
48 struct Wrap w1 = { { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
49 struct Wrap w2 = { .p = { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
50 struct Wrap w3 = { .p = { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
51 struct Wrap w4 = { { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
52 struct Wrap w5 = { .p = { 0, 1 }, .d = { .x = 2, .y = 3} };
53 
54 struct Wrap w6 = { { 0, 1 }, .d.x = 2, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
55 struct Wrap w7 = { .p = { 0, 1 }, .d.x = 2, .d.y = 3 };
56 struct Wrap w8 = { .p = { 0, 1 }, .d = { 2, 0 }, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
57 struct Wrap w9 = { .p = { 0, 1 }, .d = { .x = 2 }, .d.y = 3 };
58 
fw1(void)59 struct Wrap fw1 (void)
60 {
61   return (struct Wrap) { { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
62 };
63 
fw2(void)64 struct Wrap fw2 (void)
65 {
66   return (struct Wrap) { .p = { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
67 }
68 
fw3(void)69 struct Wrap fw3 (void)
70 {
71   return (struct Wrap) { .p = { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
72 }
73 
fw4(void)74 struct Wrap fw4 (void)
75 {
76   return (struct Wrap) { { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
77 }
78 
fw5(void)79 struct Wrap fw5 (void)
80 {
81   return (struct Wrap) { .p = { 0, 1 }, .d = { .x = 2, .y = 3} };
82 }
83 
fw6(void)84 struct Wrap fw6 (void)
85 {
86   return (struct Wrap) { { 0, 1 }, .d.x = 2, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
87 }
88 
fw7(void)89 struct Wrap fw7 (void)
90 {
91   return (struct Wrap) { .p = { 0, 1 }, .d.x = 2, .d.y = 3 };
92 }
93 
fw8(void)94 struct Wrap fw8 (void)
95 {
96   return (struct Wrap) { .p = { 0, 1 }, .d = { 2, 0 }, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
97 }
98 
fw9(void)99 struct Wrap fw9 (void)
100 {
101   return (struct Wrap) { .p = { 0, 1 }, .d = { .x = 2 }, .d.y = 3 };
102 }
103 
104 struct Des da[] = {
105   { .x = 1, .y = 2 },
106   { 5, 5 } /* { dg-warning "(positional|near initialization)" } */
107 };
108