aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decl.c36
-rw-r--r--token.c1
2 files changed, 23 insertions, 14 deletions
diff --git a/decl.c b/decl.c
index ae4f765..1020c2a 100644
--- a/decl.c
+++ b/decl.c
@@ -864,6 +864,27 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
return d;
}
+static bool
+staticassert(struct scope *s)
+{
+ struct expr *e;
+ uint64_t c;
+
+ if (!consume(T_STATIC_ASSERT))
+ return false;
+ expect(TLPAREN, "after _Static_assert");
+ c = intconstexpr(s, true);
+ expect(TCOMMA, "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: %.*s", (int)e->base->string.size, e->base->string.data);
+ expect(TRPAREN, "after static assertion message");
+ expect(TSEMICOLON, "after static assertion");
+ return true;
+}
+
bool
decl(struct scope *s, struct func *f)
{
@@ -878,23 +899,10 @@ 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;
- if (consume(T_STATIC_ASSERT)) {
- expect(TLPAREN, "after _Static_assert");
- c = intconstexpr(s, true);
- expect(TCOMMA, "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: %.*s", (int)e->base->string.size, e->base->string.data);
- expect(TRPAREN, "after static assertion message");
- expect(TSEMICOLON, "after static assertion");
+ if (staticassert(s))
return true;
- }
base = declspecs(s, &sc, &fs, &align);
if (!base.type)
return false;
diff --git a/token.c b/token.c
index 47d918e..5e1a977 100644
--- a/token.c
+++ b/token.c
@@ -56,6 +56,7 @@ const char *tokstr[] = {
[T_STATIC_ASSERT] = "_Static_assert",
[T_THREAD_LOCAL] = "_Thread_local",
[T__ASM__] = "__asm__",
+ [T__ATTRIBUTE__] = "__attribute__",
[T__TYPEOF__] = "__typeof__",
/* punctuator */