| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-options "" } |
| 3 |
// Test C++17 selection statements with initializer, basic use. |
| 4 |
|
| 5 |
extern int foo (void); |
| 6 |
extern void bar (int); |
| 7 |
extern int g; |
| 8 |
|
| 9 |
void |
| 10 |
f (void) |
| 11 |
{ |
| 12 |
if (auto p = foo (); p > 10) |
| 13 |
bar (p); |
| 14 |
else |
| 15 |
bar (-p); |
| 16 |
|
| 17 |
if ((g += 2); g > 6) |
| 18 |
bar (1); |
| 19 |
|
| 20 |
if (auto a = 9, b = foo (); a + b > 10) |
| 21 |
bar (a + b); |
| 22 |
else |
| 23 |
bar (a - b); |
| 24 |
|
| 25 |
if (({ int a; 1;})) |
| 26 |
bar (0); |
| 27 |
|
| 28 |
if (auto i = foo (); i > 6) |
| 29 |
bar (0); |
| 30 |
else if (i++; i > 8) |
| 31 |
bar (1); |
| 32 |
} |
| 33 |
|
| 34 |
extern void lock (void); |
| 35 |
|
| 36 |
void |
| 37 |
f2 (int i) |
| 38 |
{ |
| 39 |
if (lock (); i > 10) |
| 40 |
++i; |
| 41 |
else |
| 42 |
--i; |
| 43 |
} |
| 44 |
|
| 45 |
void |
| 46 |
f3 (int i) |
| 47 |
{ |
| 48 |
switch (i *= 2; auto idx = i) |
| 49 |
{ |
| 50 |
case 4: |
| 51 |
bar (3); |
| 52 |
break; |
| 53 |
default: |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
void |
| 59 |
f4 (void) |
| 60 |
{ |
| 61 |
if constexpr (constexpr auto s = sizeof (int); s > 10) |
| 62 |
foo (); |
| 63 |
} |