History

A right fix for the array in struct initialization w/o '{' Parse a type if there is only one '(' before a type token. Otherwise a recursion will perform a job.

seyko committed 11 years ago

Commit bd531ec1 parent 367bb6f4 files · +116 −21Browse files

Showing the changes to tccgen.c (1 of 4 files). Show all

Unified · Split

tccgen.c+9−20
@@ -5546,33 +5546,26 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 5545 unmodified lines
55465546 s->c = array_length;
55475547 } else if ((type->t & VT_BTYPE) == VT_STRUCT &&
55485548 (sec || !first || tok == '{')) {
5549− int par_count;
55505549
55515550 /* NOTE: the previous test is a specific case for automatic
55525551 struct/union init */
55535552 /* XXX: union needs only one init */
55545553
5555− /* XXX: this test is incorrect for local initializers
5556− beginning with ( without {. It would be much more difficult
5557− to do it correctly (ideally, the expression parser should
5558− be used in all cases) */
5559− par_count = 0;
55605554 if (tok == '(') {
55615555 AttributeDef ad1;
55625556 CType type1;
55635557 next();
5564− while (tok == '(') {
5565− par_count++;
5566− next();
5567− }
5568− if (!parse_btype(&type1, &ad1))
5569− expect("cast");
5570− type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5558+ if (tok != '(') {
5559+ if (!parse_btype(&type1, &ad1))
5560+ expect("cast");
5561+ type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
55715562 #if 0
5572− if (!is_assignable_types(type, &type1))
5573− tcc_error("invalid type for cast");
5563+ if (!is_assignable_types(type, &type1))
5564+ tcc_error("invalid type for cast");
55745565 #endif
5575− skip(')');
5566+ skip(')');
5567+ } else
5568+ unget_tok(tok);
55765569 }
55775570 no_oblock = 1;
55785571 if (first || tok == '{') {
@@ -5646,10 +5639,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 67 unmodified lines
56465639 }
56475640 if (!no_oblock)
56485641 skip('}');
5649− while (par_count) {
5650− skip(')');
5651− par_count--;
5652− }
56535642 } else if (tok == '{') {
56545643 next();
56555644 decl_initializer(type, sec, c, first, size_only);

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