mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix of shadowing bug. Allow pointer and subarrays to be constant initialized. Compile time values may now pass around anything considered compile time constant. It's possible to index into an initializer list at compile time. (Some work still remains on this)
This commit is contained in:
committed by
Christoffer Lerno
parent
1b103a3e22
commit
e4c7dde30b
@@ -1394,28 +1394,9 @@ bool sema_analyse_var_decl(Context *context, Decl *decl)
|
||||
if (!sema_analyse_expr_of_required_type(context, decl->type, init_expr, false)) return false;
|
||||
|
||||
// 2. Check const-ness
|
||||
if ((is_global || decl->var.is_static) && !init_expr->constant)
|
||||
if ((is_global || decl->var.is_static) && !expr_is_constant_eval(init_expr, CONSTANT_EVAL_ANY))
|
||||
{
|
||||
// 3. Special case is when the init expression is the reference
|
||||
// to a constant global structure.
|
||||
if (init_expr->expr_kind == EXPR_CONST_IDENTIFIER)
|
||||
{
|
||||
// 4. If so we copy the init expression, which should always be constant.
|
||||
*init_expr = *init_expr->identifier_expr.decl->var.init_expr;
|
||||
assert(init_expr->constant);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (init_expr->expr_kind == EXPR_CAST)
|
||||
{
|
||||
SEMA_ERROR(init_expr, "The expression may not be a non constant cast.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SEMA_ERROR(init_expr, "The expression must be a constant value.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SEMA_ERROR(init_expr, "The expression must be a constant value.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user