Fix array pointer stringification.

`int (*)[4];` should not be stringified as `int *[4];`
Add stringification tests.
This commit is contained in:
Petr Skocik 2018-11-12 17:11:24 +01:00
parent 93a4ddfa63
commit 73ca09ff32
3 changed files with 19 additions and 1 deletions

View File

@ -2964,7 +2964,10 @@ static void type_to_str(char *buf, int buf_size,
case VT_PTR:
s = type->ref;
if (t & VT_ARRAY) {
snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);
if (varstr && '*' == *varstr)
snprintf(buf1, sizeof(buf1), "(%s)[%d]", varstr, s->c);
else
snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);
type_to_str(buf, buf_size, &s->type, buf1);
goto no_var;
}

View File

@ -118,4 +118,10 @@ enum e5;
void f3(enum e4 e);
void f3(enum e5 e);
#elif defined test_ptr_to_str
void f() { _Generic((int const *[]){0}, int:0); }
#elif defined test_fnptr_to_str
void f() { _Generic((int (*(*)(float,char))(double,int)){0}, int:0); }
#elif defined test_array_to_str
void f() { _Generic((int(*)[3]){0}, int:0); }
#endif

View File

@ -44,3 +44,12 @@
[test_enum_compat]
60_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'
[test_ptr_to_str]
60_errors_and_warnings.c:122: error: type 'const int **' does not match any association
[test_fnptr_to_str]
60_errors_and_warnings.c:124: error: type 'int (*(*)(float, char))(double, int)' does not match any association
[test_array_to_str]
60_errors_and_warnings.c:126: error: type 'int (*)[3]' does not match any association