History

Fix array pointer stringification.

`int (*)[4];` should not be stringified as `int *[4];` Add stringification tests.

Petr Skocik committed 8 years ago

Commit 73ca09f1 parent 93a4ddf3 files · +19 −1Browse files

Unified · Split

3 files
  1. tccgen.c +4 −1
  2. tests/tests2/60_errors_and_warnings.c +6 −0
  3. tests/tests2/60_errors_and_warnings.expect +9 −0
tccgen.c+4−1
@@ -2964,7 +2964,10 @@ static void type_to_str(char *buf, int buf_size, · 2963 unmodified lines
2964 case VT_PTR:2964 case VT_PTR:
2965 s = type->ref;2965 s = type->ref;
2966 if (t & VT_ARRAY) {2966 if (t & VT_ARRAY) {
2967 snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);2967 if (varstr && '*' == *varstr)
2968 snprintf(buf1, sizeof(buf1), "(%s)[%d]", varstr, s->c);
2969 else
2970 snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);
2968 type_to_str(buf, buf_size, &s->type, buf1);2971 type_to_str(buf, buf_size, &s->type, buf1);
2969 goto no_var;2972 goto no_var;
2970 }2973 }
tests/tests2/60_errors_and_warnings.c+6−0
@@ -118,4 +118,10 @@ enum e5; · 117 unmodified lines
118void f3(enum e4 e);118void f3(enum e4 e);
119void f3(enum e5 e);119void f3(enum e5 e);
120 120
121#elif defined test_ptr_to_str
122void f() { _Generic((int const *[]){0}, int:0); }
123#elif defined test_fnptr_to_str
124void f() { _Generic((int (*(*)(float,char))(double,int)){0}, int:0); }
125#elif defined test_array_to_str
126void f() { _Generic((int(*)[3]){0}, int:0); }
121#endif127#endif
tests/tests2/60_errors_and_warnings.expect+9−0
@@ -44,3 +44,12 @@ · 43 unmodified lines
44 44
45[test_enum_compat]45[test_enum_compat]
4660_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'4660_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'
47
48[test_ptr_to_str]
4960_errors_and_warnings.c:122: error: type 'const int **' does not match any association
50
51[test_fnptr_to_str]
5260_errors_and_warnings.c:124: error: type 'int (*(*)(float, char))(double, int)' does not match any association
53
54[test_array_to_str]
5560_errors_and_warnings.c:126: error: type 'int (*)[3]' does not match any association

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t