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
29642964 case VT_PTR:
29652965 s = type->ref;
29662966 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);
29682971 type_to_str(buf, buf_size, &s->type, buf1);
29692972 goto no_var;
29702973 }
tests/tests2/60_errors_and_warnings.c+6−0
@@ -118,4 +118,10 @@ enum e5; · 117 unmodified lines
118118 void f3(enum e4 e);
119119 void f3(enum e5 e);
120120
121+#elif defined test_ptr_to_str
122+void f() { _Generic((int const *[]){0}, int:0); }
123+#elif defined test_fnptr_to_str
124+void f() { _Generic((int (*(*)(float,char))(double,int)){0}, int:0); }
125+#elif defined test_array_to_str
126+void f() { _Generic((int(*)[3]){0}, int:0); }
121127 #endif
tests/tests2/60_errors_and_warnings.expect+9−0
@@ -44,3 +44,12 @@ · 43 unmodified lines
4444
4545 [test_enum_compat]
4646 60_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'
47+
48+[test_ptr_to_str]
49+60_errors_and_warnings.c:122: error: type 'const int **' does not match any association
50+
51+[test_fnptr_to_str]
52+60_errors_and_warnings.c:124: error: type 'int (*(*)(float, char))(double, int)' does not match any association
53+
54+[test_array_to_str]
55+60_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