Fix how _Generic treats pointers to arrays.

_Generic should distinguish pointers to differently sized
arrays such as `int(*)[2]` and `int(*)[4]`.
This commit is contained in:
Petr Skocik 2018-11-12 17:19:15 +01:00
parent 73ca09ff32
commit 314843ffc3
2 changed files with 7 additions and 1 deletions

View File

@ -2820,11 +2820,14 @@ static int compare_types(CType *type1, CType *type2, int unqualified)
if (t1 != t2)
return 0;
/* test more complicated cases */
bt1 = t1 & VT_BTYPE;
bt1 = t1 & (VT_BTYPE | (unqualified ? 0 : VT_ARRAY) );
if (bt1 == VT_PTR) {
type1 = pointed_type(type1);
type2 = pointed_type(type2);
return is_compatible_types(type1, type2);
} else if (bt1 & VT_ARRAY) {
return type1->ref->c < 0 || type2->ref->c < 0
|| type1->ref->c == type2->ref->c;
} else if (bt1 == VT_STRUCT) {
return (type1->ref == type2->ref);
} else if (bt1 == VT_FUNC) {

View File

@ -68,5 +68,8 @@ int main()
printf("%d\n", i);
i = _Generic(foo, fptr: 3, int: 4);
printf("%d\n", i);
(void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
return 0;
}