Allow inline enum values to define sizes.

This commit is contained in:
Christoffer Lerno
2025-02-04 00:23:59 +01:00
parent aaa5c0f743
commit c54c400291
3 changed files with 9 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ bool sema_resolve_array_like_len(SemaContext *context, TypeInfo *type_info, Arra
Expr *len_expr = type_info->array.len;
// Analyse it.
if (!sema_analyse_expr(context, len_expr)) return type_info_poison(type_info);
if (!sema_analyse_expr_rhs(context, type_isz, len_expr, false, NULL, false)) return type_info_poison(type_info);
// A constant expression is assumed.
if (!sema_cast_const(len_expr))

View File

@@ -3,7 +3,7 @@ const int CONSTANT = 1;
int[CONSTANT] a2;
int[3] a3 = { [CONSTANT] = 1 };
const bool B = true;
int[B] c2; // #error: Expected an integer
int[B] c2; // #error: cannot implicitly be converted
int non_constant = 10;
int[non_constant] b; // #error: Expected a constant value as

View File

@@ -0,0 +1,7 @@
enum Bar : inline usz
{
FOO,
BAR,
}
int[Bar.BAR] x;