More fixes for typedef @constinit change

This commit is contained in:
Christoffer Lerno
2026-02-14 01:37:53 +01:00
parent fac9054f1b
commit eb80776988
20 changed files with 199 additions and 176 deletions

View File

@@ -1466,7 +1466,18 @@ static bool rule_to_distinct(CastContext *cc, bool is_explicit, bool is_silent)
cc->to_group = flat_group;
// If it's silent or explicit, just run it:
if (is_silent || is_explicit) return cast_is_allowed(cc, is_explicit, is_silent);
if (is_silent || is_explicit)
{
if (!cast_is_allowed(cc, is_explicit, is_silent)) return false;
if (!is_explicit && !cc->is_binary_conversion && !to_type->decl->attr_constinit && !expr_is_const_untyped_list(cc->expr))
{
if (compiler.build.warnings.deprecation == WARNING_ERROR)
{
return sema_cast_error(cc, cast_is_allowed(cc, true, true), is_silent);
}
}
return true;
}
// Loud and implicit:
if (cast_is_allowed(cc, false, true))
{

View File

@@ -1798,10 +1798,10 @@ ERR:
return false;
}
bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl)
static bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl, Type *underlying_type)
{
Expr *value = decl->enum_constant.value;
if (!sema_analyse_inferred_expr(context, decl->type, value, NULL)) return decl_poison(decl);
if (!sema_analyse_expr_rhs(context, decl->type, value, false, NULL, true)) return decl_poison(decl);
if (!expr_is_runtime_const(value))
{
SEMA_ERROR(value, "Expected an constant enum value.");
@@ -1809,8 +1809,8 @@ bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl)
}
if (value->type != decl->type)
{
if (!cast_implicit_binary(context, value, decl->type, NULL)) return decl_poison(decl);
cast_explicit_silent(context, value, decl->type);
SEMA_ERROR(value, "Expected an constant enum value of type %s, was %s", type_quoted_error_string(decl->type), type_quoted_error_string(value->type));
return decl_poison(decl);
}
return true;
}
@@ -1901,7 +1901,7 @@ static inline bool sema_analyse_raw_enum(SemaContext *context, Decl *decl, bool
{
Decl *enum_value = enum_values[i];
enum_value->resolve_status = RESOLVE_RUNNING;
if (!sema_analyse_const_enum_constant_val(context, enum_value)) return decl_poison(decl);
if (!sema_analyse_const_enum_constant_val(context, enum_value, type)) return decl_poison(decl);
enum_value->resolve_status = RESOLVE_DONE;
}
return success;

View File

@@ -7054,6 +7054,18 @@ bool sema_expr_analyse_assign_right_side(SemaContext *context, Expr *expr, Type
// 1. Evaluate right side to required type.
bool to_optional = left_type && type_is_optional(left_type);
if (is_declaration && left_type)
{
switch (left_type->type_kind)
{
case TYPE_TYPEDEF:
case TYPE_CONST_ENUM:
is_declaration = false;
break;
default:
break;
}
}
if (!sema_analyse_expr_rhs(context, left_type, right, is_unwrapped_var || to_optional, failed_ref, is_declaration)) return false;
if (IS_OPTIONAL(right) && !to_optional)
{

View File

@@ -137,7 +137,6 @@ INLINE bool sema_set_alignment(SemaContext *context, Type *type, AlignSize *resu
INLINE bool sema_set_alloca_alignment(SemaContext *context, Type *type, AlignSize *result);
INLINE void sema_display_deprecated_warning_on_use(SemaContext *context, Decl *decl, SourceSpan span);
bool sema_expr_analyse_ct_concat(SemaContext *context, Expr *concat_expr, Expr *left, Expr *right, bool *failed_ref);
bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl);
bool sema_analyse_attributes(SemaContext *context, Decl *decl, Attr **attrs, AttributeDomain domain, bool *erase_decl);
void unit_register_optional_global_decl(CompilationUnit *unit, Decl *decl);

View File

@@ -8,7 +8,8 @@
#include <sys/resource.h>
#endif
#if PLATFORM_WINDOWS
#include <windows.h>
extern bool SetConsoleCP(uint32_t codepage);
extern bool SetConsoleOutputCP(uint32_t codepage);
#endif
bool debug_log = false;