aboutsummaryrefslogtreecommitdiff
path: root/decl.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-06-28 20:31:11 -0700
committerMichael Forney <mforney@mforney.org>2021-06-28 20:31:11 -0700
commitc16f07acf655b9f4fb006d8256b4027fb5a13aa8 (patch)
tree7b272c7a4db339ba87e4a2cd20c455e582eb05b0 /decl.c
parentfb10b3671f41a3e09837fd07b90da9c25a1bbf57 (diff)
Add stringconcat function to concatenate adjacent string literals
This function also ensures that the string prefixes (if any) are compatible. It should make it easier to implement wide string support.
Diffstat (limited to 'decl.c')
-rw-r--r--decl.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/decl.c b/decl.c
index 0d47b8e..ea62f56 100644
--- a/decl.c
+++ b/decl.c
@@ -753,19 +753,18 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, ui
static bool
staticassert(struct scope *s)
{
- struct expr *e;
uint64_t c;
+ char *msg;
if (!consume(T_STATIC_ASSERT))
return false;
expect(TLPAREN, "after _Static_assert");
c = intconstexpr(s, true);
if (consume(TCOMMA)) {
- e = assignexpr(s);
- if (!e->decayed || e->base->kind != EXPRSTRING)
- error(&tok.loc, "expected string literal after static assertion expression");
+ tokencheck(&tok, TSTRINGLIT, "after static assertion expression");
+ msg = stringconcat();
if (!c)
- error(&tok.loc, "static assertion failed: %.*s", (int)e->base->string.size, e->base->string.data);
+ error(&tok.loc, "static assertion failed: %s", msg + (*msg != '"'));
} else if (!c) {
error(&tok.loc, "static assertion failed");
}