diff options
-rw-r--r-- | init.c | 36 | ||||
-rw-r--r-- | test/initializer-string-braces.c | 1 | ||||
-rw-r--r-- | test/initializer-string-braces.qbe | 1 |
3 files changed, 20 insertions, 18 deletions
@@ -163,8 +163,6 @@ focus(struct initparser *p) p->sub->mem = p->sub->type->structunion.members; t = p->sub->mem->type; break; - default: - t = p->sub->type; } subobj(p, t, 0); } @@ -224,13 +222,16 @@ parseinit(struct scope *s, struct type *t) designator(s, &p); else if (p.sub != p.cur) advance(&p); - else + else if (p.cur->type->kind == TYPESTRUCT || p.cur->type->kind == TYPEUNION) focus(&p); } - if (tok.kind == TLBRACE) { - next(); - if (p.cur && p.cur->type == p.sub->type) - error(&tok.loc, "nested braces around scalar initializer"); + if (consume(TLBRACE)) { + if (p.cur == p.sub) { + if (p.cur->type->prop & PROPSCALAR) + error(&tok.loc, "nested braces around scalar initializer"); + assert(p.cur->type->kind == TYPEARRAY); + focus(&p); + } p.cur = p.sub; p.cur->iscur = true; continue; @@ -240,17 +241,16 @@ parseinit(struct scope *s, struct type *t) t = p.sub->type; switch (t->kind) { case TYPEARRAY: - if (expr->decayed && expr->base->kind == EXPRSTRING) { - expr = expr->base; - base = t->base; - /* XXX: wide string literals */ - if (!(base->prop & PROPCHAR)) - error(&tok.loc, "array initializer is string literal with incompatible type"); - if (t->incomplete) - updatearray(t, expr->string.size); - goto add; - } - break; + if (!expr->decayed || expr->base->kind != EXPRSTRING) + break; + base = t->base; + /* XXX: wide string literals */ + if (!(base->prop & PROPCHAR)) + break; + expr = expr->base; + if (t->incomplete) + updatearray(t, expr->string.size); + goto add; case TYPESTRUCT: case TYPEUNION: if (typecompatible(expr->type, t)) diff --git a/test/initializer-string-braces.c b/test/initializer-string-braces.c new file mode 100644 index 0000000..e540d5e --- /dev/null +++ b/test/initializer-string-braces.c @@ -0,0 +1 @@ +char s[] = {"abc"}; diff --git a/test/initializer-string-braces.qbe b/test/initializer-string-braces.qbe new file mode 100644 index 0000000..46be123 --- /dev/null +++ b/test/initializer-string-braces.qbe @@ -0,0 +1 @@ +export data $s = align 1 { b "abc", z 1, } |