https://gcc.gnu.org/g:9bbec965c9b781b6e7733ff92012701b805ab084
commit r17-867-g9bbec965c9b781b6e7733ff92012701b805ab084 Author: Eric Botcazou <[email protected]> Date: Mon Feb 23 17:29:44 2026 +0100 ada: Adjust 'Constrained for formal parameters of unchecked union types GNAT has historically never added extra formal parameters alongside formal parameters of unchecked union types, even when they have convention Ada, so it cannot compute the 'Constrained attribute for In Out or Out formal parameters. This changes the compiler to raise Program_Error in this case. gcc/ada/ChangeLog: * exp_attr.adb (Expand_N_Attribute_Reference) <Constrained>: If the prefix is a non-In formal parameter of an unchecked union type, give a warning and insert a raise statement for Program_Error. Diff: --- gcc/ada/exp_attr.adb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 64a4559dff71..403b5899ce5e 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -3554,6 +3554,25 @@ package body Exp_Attr is New_Occurrence_Of (Extra_Constrained (Formal_Ent), Loc)); + -- Extra formals are not created for Unchecked_Union parameters + + elsif Present (Formal_Ent) + and then Ekind (Formal_Ent) /= E_In_Parameter + and then Is_Unchecked_Union (Base_Type (Etype (Formal_Ent))) + then + if Comes_From_Source (N) then + Error_Msg_N + ("constraints cannot be determined for Unchecked_Union??", N); + Error_Msg_N + ("\Program_Error will be raised for ''Constrained??", N); + end if; + + Insert_Action (N, + Make_Raise_Program_Error (Loc, + Reason => PE_Unchecked_Union_Restriction)); + + Rewrite (N, New_Occurrence_Of (Boolean_Literals (False), Loc)); + -- If the prefix is an access to object, the attribute applies to -- the designated object, so rewrite with an explicit dereference.
