Allow limited type initialization via constructors.
Ada now supports initializing limited types using constructors, enhancing type safety and flexibility.
This significant update to Ada allows the initialization of limited types through constructors, a feature previously unavailable. The change involves extensive modifications across the Ada front-end, including error messaging improvements for constructor names, promotion of Replace_With_Attribute_Definition to a public function, and updates to how allocators and parameterless constructors are handled. This expands the utility of constructors, providing a more robust and idiomatic way to manage initialization for limited types, which cannot be copied or assigned after declaration.
In Details
This commit expands the GCC Ada front-end's constructor support to encompass limited types. Previously, initializing limited types via constructors posed challenges due to restrictions on their copy and assignment semantics. The changes primarily affect exp_attr.adb (Attribute_Make for handling assignments and declarations), exp_ch4.adb (allocators), and sem_ch3.adb (OK_For_Limited_Init_In_05 now accepts T'Make). Replace_With_Attribute_Definition is refactored from nested to package-level visibility for broader utility in errout.adb. The core challenge lies in ensuring that co…
For Context
In Ada, a 'limited type' is a special kind of data structure that, once created, cannot be copied or assigned to another variable of the same type. This strictness helps ensure certain guarantees, for instance, preventing accidental duplication of unique resources. A 'constructor' is a special function used to properly set up a new instance of a data structure. This update makes it possible to use constructors to initialize limited types. Before this change, initializing limited types was more restrictive. Now, developers have a more controlled and expressive way to create and set up these unique data structures, aligning with modern programming practices and improving safety by ensuring correct initial states without resorting to less idiomatic workarounds. This involves many internal compiler updates to correctly handle how these types are created and their initial values are set.