Raise Program_Error for 'Constrained attribute on unchecked union parameters
The Ada compiler now raises Program_Error for the 'Constrained attribute when applied to non-In formal parameters of unchecked union types.
GNAT historically hasn’t added extra formal parameters alongside formal parameters of unchecked union types, preventing computation of the ‘Constrained attribute for In Out or Out formal parameters. The compiler now raises Program_Error in these cases to enforce correct usage and prevent unexpected behavior. This change affects code that uses unchecked unions with the ‘Constrained attribute.
In Details
The Ada compiler now raises Program_Error when the 'Constrained attribute is applied to non-In formal parameters of unchecked union types. GNAT historically hasn't added extra formal parameters alongside unchecked union types, so the compiler cannot compute the 'Constrained attribute for In Out or Out formal parameters. This change affects code that uses unchecked unions with the 'Constrained attribute.
For Context
In Ada, unchecked unions allow you to treat the same memory location as different data types, without explicit type conversion. The 'Constrained attribute checks whether a type has a fixed size and layout. This commit addresses a case where the compiler couldn't determine if certain unchecked union types had a fixed size. Now, the compiler will raise a Program_Error, indicating a potential issue that needs to be addressed by the developer, mainly that the compiler cannot check the bounds.