From 1df176029efa0d1e971e8835178f254ab8881592 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 12 Mar 2019 18:59:35 -0700 Subject: Allow string literals to initialize any array with character type --- init.c | 3 ++- tests/initializer-unsigned-string.c | 1 + tests/initializer-unsigned-string.qbe | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/initializer-unsigned-string.c create mode 100644 tests/initializer-unsigned-string.qbe diff --git a/init.c b/init.c index 3e11c71..27498b2 100644 --- a/init.c +++ b/init.c @@ -249,7 +249,8 @@ parseinit(struct scope *s, struct type *t) if (expr->flags & EXPRFLAG_DECAYED && expr->unary.base->kind == EXPRSTRING) { expr = expr->unary.base; base = typeunqual(t->base, NULL); - if (!typecompatible(expr->type->base, base)) + /* XXX: wide string literals */ + if (!(typeprop(base) & PROPCHAR)) error(&tok.loc, "array initializer is string literal with incompatible type"); if (t->incomplete) updatearray(t, expr->string.size); diff --git a/tests/initializer-unsigned-string.c b/tests/initializer-unsigned-string.c new file mode 100644 index 0000000..a932889 --- /dev/null +++ b/tests/initializer-unsigned-string.c @@ -0,0 +1 @@ +unsigned char s[] = "abc"; diff --git a/tests/initializer-unsigned-string.qbe b/tests/initializer-unsigned-string.qbe new file mode 100644 index 0000000..46be123 --- /dev/null +++ b/tests/initializer-unsigned-string.qbe @@ -0,0 +1 @@ +export data $s = align 1 { b "abc", z 1, } -- cgit v1.2.3