- Change typedef and const enums to not convert from literals by default. (#2934)

- Add `@constinit` to allow old typedef behaviour.
This commit is contained in:
Christoffer Lerno
2026-02-13 20:39:47 +01:00
committed by GitHub
parent bbf89815d6
commit e299a4b630
12 changed files with 37 additions and 19 deletions

View File

@@ -3128,6 +3128,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_
[ATTRIBUTE_CNAME] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES,
[ATTRIBUTE_COMPACT] = ATTR_STRUCT | ATTR_UNION,
[ATTRIBUTE_CONST] = ATTR_MACRO,
[ATTRIBUTE_CONSTINIT] = ATTR_TYPEDEF | ATTR_ENUM,
[ATTRIBUTE_DEPRECATED] = USER_DEFINED_TYPES | CALLABLE_TYPE | ATTR_CONST | ATTR_GLOBAL | ATTR_MEMBER | ATTR_BITSTRUCT_MEMBER | ATTR_INTERFACE | ATTR_ALIAS,
[ATTRIBUTE_DYNAMIC] = ATTR_FUNC,
[ATTRIBUTE_EXPORT] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_ALIAS,
@@ -3471,6 +3472,9 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_
case ATTRIBUTE_STRUCTLIKE:
decl->attr_structlike = true;
return true;
case ATTRIBUTE_CONSTINIT:
decl->attr_constinit = true;
return true;
case ATTRIBUTE_SIMD:
RETURN_SEMA_ERROR(attr, "'@simd' is only allowed on typedef types.");
case ATTRIBUTE_SECTION: