1 // PR c++/77467
2 // { dg-do compile { target c++14 } }
3 
4 constexpr int
foo(const int x,const unsigned n)5 foo (const int x, const unsigned n) noexcept
6 {
7   switch (n)
8     {
9     case 0:
10       return 1;
11     case 1:
12       return x;
13     default:
14       const auto m = (n >> 1);
15       const auto y = foo (x, m);
16       return ((m << 1) == n) ? y * y : x * y * y;
17     }
18 }
19 
20 static_assert (foo (3, 2) == 9, "");
21 static_assert (foo (2, 3) == 8, "");
22 
23 constexpr int
bar(int x)24 bar (int x)
25 {
26   int a = x;
27   switch (x)
28     a = x + 1;
29   return a;
30 }
31 
32 static_assert (bar (0) == 0, "");
33 static_assert (bar (1) == 1, "");
34 
35 constexpr int
baz(const int x,int y)36 baz (const int x, int y) noexcept
37 {
38   switch (x)
39     {
40     case 0:
41       return 1;
42     case 1:
43       return x;
44     case 2:
45       if ((y += 2) == 0)
46 	{
47 	case 3:
48 	  y += 4;
49 	  break;
50 	}
51       else
52 	{
53 	case 4:
54 	  y += 8;
55 	  break;
56 	}
57       break;
58     case 5:
59       for (y = 0; y < 3; y++)
60 	{
61 	case 7:
62 	  if (y == -4)
63 	    y += 3;
64 	  if (y == -3)
65 	    continue;
66 	  if (y == -2)
67 	    {
68 	      y += 18;
69 	      break;
70 	    }
71 	  if (y == 2)
72 	    {
73 	    case 6:
74 	      y += 12;
75 	    default:
76 	      y++;
77 	      break;
78 	    }
79 	}
80       break;
81     case -1:
82     case -2:
83       switch (y)
84 	{
85 	case 19:
86 	  y += 2;
87 	  break;
88 	case 20:
89 	  y += 3;
90 	  if (x == 2)
91 	    case 21:;
92 	  y += 2;
93 	  if (x == 3)
94 	    default:;
95 	  y += 4;
96 	  break;
97 	}
98       return x + y + 1;
99     }
100   return x + y;
101 }
102 
103 static_assert (baz (0, 7) == 1, "");
104 static_assert (baz (1, 7) == 1, "");
105 static_assert (baz (2, -2) == 6, "");
106 static_assert (baz (2, 0) == 12, "");
107 static_assert (baz (3, 1) == 8, "");
108 static_assert (baz (4, 2) == 14, "");
109 static_assert (baz (5, -20) == 20, "");
110 static_assert (baz (6, 5) == 24, "");
111 static_assert (baz (7, -5) == 22, "");
112 static_assert (baz (7, -4) == 22, "");
113 static_assert (baz (7, -3) == 23, "");
114 static_assert (baz (7, -2) == 23, "");
115 static_assert (baz (7, -1) == 22, "");
116 static_assert (baz (7, 0) == 22, "");
117 static_assert (baz (7, 2) == 22, "");
118 static_assert (baz (7, 6) == 14, "");
119 static_assert (baz (8, 9) == 18, "");
120 static_assert (baz (8, -2) == 7, "");
121 static_assert (baz (-1, 19) == 21, "");
122 static_assert (baz (-1, 20) == 29, "");
123 static_assert (baz (-1, 21) == 27, "");
124 static_assert (baz (-1, 5) == 9, "");
125 static_assert (baz (-2, 19) == 20, "");
126 static_assert (baz (-2, 20) == 28, "");
127 static_assert (baz (-2, 21) == 26, "");
128 static_assert (baz (-2, 5) == 8, "");
129