diff options
Diffstat (limited to 'types.c')
-rw-r--r-- | types.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -2605,7 +2605,8 @@ static Status types_expr(Typer *tr, Expression *e) { case UNARY_DALIGNOF: { Type *queried_type; if (!type_is_builtin(&of->type, BUILTIN_TYPE)) { - err_print(e->where, "Argument of #sizeof or #alignof must be a Type. Did you mean #sizeof(typeof ...)?"); + char *s = e->unary.op == UNARY_DSIZEOF ? "sizeof" : "alignof"; + err_print(e->where, "Argument of #%s must be a Type. Did you mean #%s(typeof ...)?", s, s); return false; } Value val; @@ -2620,6 +2621,22 @@ static Status types_expr(Typer *tr, Expression *e) { t->kind = TYPE_BUILTIN; t->builtin = BUILTIN_I64; } break; + case UNARY_SIZEOF: + case UNARY_ALIGNOF: { + /* eval of */ + if (!type_is_builtin(&of->type, BUILTIN_TYPE)) { + char *s = e->unary.op == UNARY_SIZEOF ? "sizeof" : "alignof"; + err_print(e->where, "Argument of %s must be a Type. Did you mean %s(typeof ...)?", s, s); + return false; + } + Value val; + if (!eval_expr(tr->evalr, of, &val)) + return false; + of->kind = EXPR_VAL; + of->val = val; + t->kind = TYPE_BUILTIN; + t->builtin = BUILTIN_I64; + } break; } } break; case EXPR_BINARY_OP: { |