This _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0); should compile like it does in gcc and clang.
Unified · Split
| @@ -5565,7 +5565,10 @@ static void expr_cond(void) · 5564 unmodified lines | |||
| 5565 | if (!g) | 5565 | if (!g) |
| 5566 | gexpr(); | 5566 | gexpr(); |
| 5567 | 5567 | ||
| 5568 | type1 = vtop->type; | 5568 | if ( ((type1=vtop->type).t&VT_BTYPE)==VT_FUNC ) { |
| 5569 | mk_pointer(&vtop->type); | ||
| 5570 | type1=vtop->type; | ||
| 5571 | } | ||
| 5569 | sv = *vtop; /* save value to handle it later */ | 5572 | sv = *vtop; /* save value to handle it later */ |
| 5570 | vtop--; /* no vpop so that FP stack is not flushed */ | 5573 | vtop--; /* no vpop so that FP stack is not flushed */ |
| 5571 | skip(':'); | 5574 | skip(':'); |
| @@ -5583,7 +5586,10 @@ static void expr_cond(void) · 11 unmodified lines | |||
| 5583 | if (c == 1) | 5586 | if (c == 1) |
| 5584 | nocode_wanted--; | 5587 | nocode_wanted--; |
| 5585 | 5588 | ||
| 5586 | type2 = vtop->type; | 5589 | if ( ((type2=vtop->type).t&VT_BTYPE)==VT_FUNC ) { |
| 5590 | mk_pointer(&vtop->type); | ||
| 5591 | type2=vtop->type; | ||
| 5592 | } | ||
| 5587 | t1 = type1.t; | 5593 | t1 = type1.t; |
| 5588 | bt1 = t1 & VT_BTYPE; | 5594 | bt1 = t1 & VT_BTYPE; |
| 5589 | t2 = type2.t; | 5595 | t2 = type2.t; |
| @@ -5643,9 +5649,6 @@ static void expr_cond(void) · 53 unmodified lines | |||
| 5643 | 0<pointed_type(&type1)->ref->c ? | 5649 | 0<pointed_type(&type1)->ref->c ? |
| 5644 | pointed_type(&type1)->ref->c : pointed_type(&type2)->ref->c; | 5650 | pointed_type(&type1)->ref->c : pointed_type(&type2)->ref->c; |
| 5645 | } | 5651 | } |
| 5646 | } else if (bt1 == VT_FUNC || bt2 == VT_FUNC) { | ||
| 5647 | /* XXX: test function pointer compatibility */ | ||
| 5648 | type = bt1 == VT_FUNC ? type1 : type2; | ||
| 5649 | } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { | 5652 | } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { |
| 5650 | /* XXX: test structure compatibility */ | 5653 | /* XXX: test structure compatibility */ |
| 5651 | type = bt1 == VT_STRUCT ? type1 : type2; | 5654 | type = bt1 == VT_STRUCT ? type1 : type2; |
| @@ -1,6 +1,27 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | #include <assert.h> | 2 | #include <assert.h> |
| 3 | 3 | ||
| 4 | char arr[1]; | ||
| 5 | static void f (void){} | ||
| 6 | void (*fp)(void) = f; | ||
| 7 | void call_fp() | ||
| 8 | { | ||
| 9 | (fp?f:f)(); | ||
| 10 | (fp?fp:fp)(); | ||
| 11 | (fp?fp:&f)(); | ||
| 12 | (fp?&f:fp)(); | ||
| 13 | (fp?&f:&f)(); | ||
| 14 | _Generic(0?arr:arr, char*: (void)0); | ||
| 15 | _Generic(0?&arr[0]:arr, char*: (void)0); | ||
| 16 | _Generic(0?arr:&arr[0], char*: (void)0); | ||
| 17 | _Generic(1?arr:arr, char*: (void)0); | ||
| 18 | _Generic(1?&arr[0]:arr, char*: (void)0); | ||
| 19 | _Generic(1?arr:&arr[0], char*: (void)0); | ||
| 20 | _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0); | ||
| 21 | (fp?&f:f)(); | ||
| 22 | (fp?f:&f)(); | ||
| 23 | } | ||
| 24 | |||
| 4 | int main() | 25 | int main() |
| 5 | { | 26 | { |
| 6 | int Count; | 27 | int Count; |