C++: Clarify array and class initialization with designators
Improves handling of designated initializers in C++ array and class initialization.
This commit refines how C++ handles designators within initializer lists, particularly for arrays and classes. It clarifies that a designator in reshape_init_r refers to a member of the current type, necessitating a brace elision if it’s not the first initializer. The changes also adjust reshape_init_array_1 and reshape_init_class to correctly interpret designators, ensuring that when a designator is present and the type is a class or array, the initialization is treated as element-specific and not an attempt to initialize the type itself directly.
In Details
This patch clarifies the handling of designators in reshape_init_r when initializing class or array types. Previously, the logic for distinguishing between initializing an element and initializing the aggregate itself was less clear, especially when designators were involved. The change ensures that if a designator is present, it unambiguously targets a member or element. If the target type is a class or array, and a designator is used, it implies initialization of a specific element within that class or array, preventing incorrect elision or initialization attempts on the aggregate type it…
- initializer list
- A C++ feature that allows aggregate types (arrays, structs, classes) to be initialized with a list of values enclosed in braces
{}. It can also be used for brace elision. - designator
- A feature in C99 and C++ that allows explicit naming of elements or members within an initializer list, e.g.,
{.member = value}or[index] = value. This provides more control over which parts of an aggregate are initialized. - brace elision
- A C++ feature where braces
{}can be omitted in an initializer list if the list is not exhaustive and the compiler can infer the remaining values (e.g., default initialization or zero-initialization). - reshape_init_r
- An internal GCC function responsible for handling recursive initialization of aggregate types, particularly arrays and classes, within the C++ frontend.