char **argv; _Generic(argv, char**: (void)0); _Generic(0?(char const*)0:argv[0], char const*: (void)0); _Generic(argv, char**: (void)0); would fail because the type of argv would get modified by the ternary. Now allocate a separate type on the value stack to prevent this error.
Unified · Split
| @@ -5627,6 +5627,12 @@ static void expr_cond(void) · 5626 unmodified lines | ||
| 5627 | 5627 | if(!compare_types(pointed_type(&type1), pointed_type(&type2),1/*unqualif*/)) |
| 5628 | 5628 | tcc_warning("pointer type mismatch in conditional expression\n"); |
| 5629 | 5629 | } |
| 5630 | + { /*copy the pointer target symbol*/ | |
| 5631 | + Sym *s; | |
| 5632 | + s = sym_push(SYM_FIELD, pointed_type(&type), 0, -1); | |
| 5633 | + type.t = VT_PTR | (type.t & VT_STORAGE); | |
| 5634 | + type.ref = s; | |
| 5635 | + } | |
| 5630 | 5636 | /*qualifs combine*/ |
| 5631 | 5637 | pointed_type(&type)->t |= 0 |
| 5632 | 5638 | |(pointed_type(&type1)->t&(VT_CONSTANT|VT_VOLATILE)) |
| @@ -95,5 +95,12 @@ int main() · 94 unmodified lines | ||
| 95 | 95 | (void)(sizeof(struct { int x:_Generic( 0?(int (*)[4])0 : (int (*)[])0, int (*)[4]:+1, int (*)[5]:(void)0); })); |
| 96 | 96 | (void)(sizeof(struct { int x:_Generic( 0?(int (*)[])0 : (int (*)[4])0, int (*)[4]:+1, int (*)[5]:(void)0); })); |
| 97 | 97 | |
| 98 | + { | |
| 99 | + char **argv; | |
| 100 | + _Generic(argv, char**: (void)0); | |
| 101 | + _Generic(0?(char const*)0:argv[0], char const*: (void)0); | |
| 102 | + _Generic(argv, char**: (void)0); | |
| 103 | + } | |
| 104 | + | |
| 98 | 105 | return 0; |
| 99 | 106 | } |