https://gcc.gnu.org/g:f466f96189b88df74d0f1fcac17b4fb0371aca0b
commit r16-9002-gf466f96189b88df74d0f1fcac17b4fb0371aca0b 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 24f618c718ae..23fe9d4b5361 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -3553,6 +3553,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.
