c++, coroutines: Simplify separation of the user function body and ramp.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-reinterpret4.C
blob9aaa6e463bc6887ec7bae50d67330a7adc5028de
1 // PR c++/113545
2 // { dg-do compile { target c++14 } }
4 char foo;
6 // This one caught a call to gcc_unreachable in
7 // cp/constexpr.cc:label_matches, when passed a convert_expr from the
8 // cast in the call.
9 constexpr unsigned char swbar(__UINTPTR_TYPE__ baz)
11   switch (baz)
12     {
13     case 13:
14       return 11;
15     case 14:
16       return 78;
17     case 2048:
18       return 13;
19     default:
20       return 42;
21     }
24 // For reference, the equivalent* if-statements.
25 constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz)
27   if (baz == 13)
28     return 11;
29   else if (baz == 14)
30     return 78;
31   else if (baz == 2048)
32     return 13;
33   else
34     return 42;
37 __attribute__ ((__noipa__))
38 void xyzzy(int x)
40   if (x != 42)
41     __builtin_abort ();
44 int main()
46   unsigned constexpr char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
47   xyzzy(c);
48   unsigned constexpr char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
49   xyzzy(d);
50   unsigned constexpr char e = swbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
51   xyzzy(e);
52   unsigned constexpr char f = ifbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
53   xyzzy(f);