Debian Codegraph @

gcc/testsuite/gcc.dg/c2y-if-decls-4.c

raw
1 /* N3356 - if declarations. */
2 /* PR c/117019 */
3 /* { dg-do run } */
4 /* { dg-require-effective-target sync_int_long } */
5 /* { dg-options "-std=c2y -Wc23-c2y-compat" } */
6 /* Test C2Y if declarations. Valid usages. */
7
8 int get () { return 42; }
9 int foo (int i) { return i; }
10
11 enum E { X = 1, Y };
12
13 void
14 simple ()
15 {
16 switch (int i = get ()) /* { dg-warning "if declarations before C2Y" } */
17 {
18 case 42:
19 foo (i);
20 break;
21 default:
22 __builtin_abort ();
23 }
24
25 switch (int i = 0) /* { dg-warning "if declarations before C2Y" } */
26 {
27 case 0:
28 foo (i);
29 break;
30 default:
31 __builtin_abort ();
32 }
33
34 switch (auto i = get ()) /* { dg-warning "if declarations before C2Y" } */
35 {
36 case 42:
37 foo (i);
38 break;
39 default:
40 __builtin_abort ();
41 }
42
43 switch (__typeof__(get ()) i = get ()) /* { dg-warning "if declarations before C2Y" } */
44 {
45 case 42:
46 foo (i);
47 break;
48 default:
49 __builtin_abort ();
50 }
51
52 switch (auto i = 0) /* { dg-warning "if declarations before C2Y" } */
53 {
54 case 0:
55 foo (i);
56 break;
57 default:
58 __builtin_abort ();
59 }
60
61 switch ([[maybe_unused]] int i = get ()) /* { dg-warning "if declarations before C2Y" } */
62 {
63 case 42:
64 foo (i);
65 break;
66 default:
67 __builtin_abort ();
68 }
69
70 switch (__attribute__((unused)) int i = get ()) /* { dg-warning "if declarations before C2Y" } */
71 {
72 case 42:
73 foo (i);
74 break;
75 default:
76 __builtin_abort ();
77 }
78
79 switch (enum E e = X) /* { dg-warning "if declarations before C2Y" } */
80 {
81 case X:
82 foo (X);
83 break;
84 default:
85 __builtin_abort ();
86 }
87
88 switch (constexpr int i = 42) /* { dg-warning "if declarations before C2Y" } */
89 {
90 case 42:
91 foo (i);
92 break;
93 default:
94 __builtin_abort ();
95 }
96
97 switch (register int i = 0); /* { dg-warning "if declarations before C2Y" } */
98 switch (static int i = 0); /* { dg-warning "if declarations before C2Y" } */
99 switch (_Atomic int i = 0); /* { dg-warning "if declarations before C2Y" } */
100
101 double i;
102 }
103
104 void
105 expr ()
106 {
107 switch (int i = get (); i) /* { dg-warning "if declarations before C2Y" } */
108 {
109 case 42:
110 foo (i);
111 break;
112 default:
113 __builtin_abort ();
114 }
115
116 switch (auto i = get (); i) /* { dg-warning "if declarations before C2Y" } */
117 {
118 case 42:
119 foo (i);
120 break;
121 default:
122 __builtin_abort ();
123 }
124
125 switch (__typeof__(get ()) i = get (); i) /* { dg-warning "if declarations before C2Y" } */
126 {
127 case 42:
128 foo (i);
129 break;
130 default:
131 __builtin_abort ();
132 }
133
134 switch (int (*f)(int) = foo; f (42)) /* { dg-warning "if declarations before C2Y" } */
135 {
136 case 42:
137 foo (42);
138 break;
139 default:
140 __builtin_abort ();
141 }
142
143 switch ([[maybe_unused]] int i = get (); i) /* { dg-warning "if declarations before C2Y" } */
144 {
145 case 42:
146 foo (i);
147 break;
148 default:
149 __builtin_abort ();
150 }
151
152 switch (__attribute__((unused)) int i = get (); i) /* { dg-warning "if declarations before C2Y" } */
153 {
154 case 42:
155 foo (i);
156 break;
157 default:
158 __builtin_abort ();
159 }
160
161 switch (enum E e = X; e) /* { dg-warning "if declarations before C2Y" } */
162 {
163 case X:
164 foo (X);
165 break;
166 default:
167 __builtin_abort ();
168 }
169
170 switch (constexpr int i = 42; i) /* { dg-warning "if declarations before C2Y" } */
171 {
172 case 42:
173 foo (i);
174 break;
175 default:
176 __builtin_abort ();
177 }
178
179 switch (int arr[] = { 1, 2, 3}; arr[0]) /* { dg-warning "if declarations before C2Y" } */
180 {
181 case 1:
182 foo (arr[0]);
183 break;
184 default:
185 __builtin_abort ();
186 }
187
188 switch (register int i = 0; i); /* { dg-warning "if declarations before C2Y" } */
189 switch (static int i = 0; i); /* { dg-warning "if declarations before C2Y" } */
190 switch (_Atomic int i = 0; i); /* { dg-warning "if declarations before C2Y" } */
191
192 double i;
193 }
194
195 int
196 main ()
197 {
198 simple ();
199 expr ();
200 }