| 1 |
// PR c++/113545 |
| 2 |
// { dg-do run { target c++14 } } |
| 3 |
|
| 4 |
char foo; |
| 5 |
|
| 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) |
| 10 |
{ |
| 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 |
} |
| 22 |
} |
| 23 |
|
| 24 |
// For reference, the equivalent* if-statements. |
| 25 |
constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz) |
| 26 |
{ |
| 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; |
| 35 |
} |
| 36 |
|
| 37 |
__attribute__ ((__noipa__)) |
| 38 |
void xyzzy(int x) |
| 39 |
{ |
| 40 |
if (x != 42) |
| 41 |
__builtin_abort (); |
| 42 |
} |
| 43 |
|
| 44 |
int main() |
| 45 |
{ |
| 46 |
unsigned const char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); |
| 47 |
xyzzy(c); |
| 48 |
unsigned const char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); |
| 49 |
xyzzy(d); |
| 50 |
unsigned const char e = swbar((__UINTPTR_TYPE__) &foo); |
| 51 |
xyzzy(e); |
| 52 |
unsigned const char f = ifbar((__UINTPTR_TYPE__) &foo); |
| 53 |
xyzzy(f); |
| 54 |
} |