Allow constant strings as default values.

This commit is contained in:
Christoffer Lerno
2021-08-31 13:03:12 +02:00
parent 69d9775876
commit 2ff5acc2a1
2 changed files with 4 additions and 2 deletions

View File

@@ -45,7 +45,7 @@ func int print(char *message)
return 1;
}
func int println(char *message) @inline
func int println(char *message = "") @inline
{
return _puts(message);
}

View File

@@ -498,7 +498,9 @@ static inline bool sema_analyse_function_param(Context *context, Decl *param, bo
{
Expr *expr = param->var.init_expr;
if (!sema_analyse_expr_of_required_type(context, param->type, expr, false)) return false;
if (expr->expr_kind != EXPR_CONST)
Expr *inner = expr;
while (inner->expr_kind == EXPR_CAST) inner = expr->cast_expr.expr;
if (inner->expr_kind != EXPR_CONST)
{
SEMA_ERROR(expr, "Only constant expressions may be used as default values.");
return false;