cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit a373f5df29f55b42de11fc2449364c23f5b866cb
parent 37215c28312432c989b403a81b057f2770c6b532
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 10 Jul 2019 01:15:37 -0700

decl: Display message when _Static_assert fails

Diffstat:
Mdecl.c | 7+++++--
Atest/static-assert-concat.c | 1+
Atest/static-assert-concat.qbe | 0
3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/decl.c b/decl.c @@ -870,6 +870,7 @@ decl(struct scope *s, struct func *f) int allowfunc = !f; struct decl *d, *prior; enum declkind kind; + struct expr *e; uint64_t c; int align; @@ -877,9 +878,11 @@ decl(struct scope *s, struct func *f) expect(TLPAREN, "after _Static_assert"); c = intconstexpr(s, true); expect(TCOMMA, "after static assertion expression"); - expect(TSTRINGLIT, "after static assertion expression"); + e = assignexpr(s); + if (!e->decayed || e->base->kind != EXPRSTRING) + error(&tok.loc, "expected string literal after static assertion expression"); if (!c) - error(&tok.loc, "static assertion failed"); // XXX: add string here + error(&tok.loc, "static assertion failed: %.*s", (int)e->base->string.size, e->base->string.data); expect(TRPAREN, "after static assertion message"); expect(TSEMICOLON, "after static assertion"); return true; diff --git a/test/static-assert-concat.c b/test/static-assert-concat.c @@ -0,0 +1 @@ +_Static_assert(1, "abc" "def"); diff --git a/test/static-assert-concat.qbe b/test/static-assert-concat.qbe