2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1z / init-statement2.C
blobdf788172c55c9168ad2bb4b6eb5e254fa4ada632
1 // { dg-do compile { target c++17 } }
2 // { dg-options "" }
3 // Test C++17 selection statements with initializer, basic use.
5 extern int foo (void);
6 extern void bar (int);
7 extern int g;
9 void
10 f (void)
12   if (auto p = foo (); p > 10)
13     bar (p);
14   else
15     bar (-p);
17   if ((g += 2); g > 6)
18     bar (1);
20   if (auto a = 9, b = foo (); a + b > 10)
21     bar (a + b);
22   else
23     bar (a - b);
25   if (({ int a; 1;}))
26     bar (0);
28   if (auto i = foo (); i > 6)
29     bar (0);
30   else if (i++; i > 8)
31     bar (1);
34 extern void lock (void);
36 void
37 f2 (int i)
39   if (lock (); i > 10)
40     ++i;
41   else
42     --i;
45 void
46 f3 (int i)
48   switch (i *= 2; auto idx = i)
49     {
50     case 4:
51       bar (3);
52       break;
53     default:
54       break;
55     }
58 void
59 f4 (void)
61   if constexpr (constexpr auto s = sizeof (int); s > 10)
62     foo ();