https://gcc.gnu.org/g:1f31aff222994ac92b485850792a9ee6d1dd606c
commit r17-4602-g1f31aff222994ac92b485850792a9ee6d1dd606c Author: Eric Botcazou <[email protected]> Date: Wed Sep 23 11:17:53 2026 +0200 Ada: Fix missing discriminant check for view conversion in assignment The view conversion is constrained when its operand object is constrained. gcc/ada/ * checks.adb (Apply_Discriminant_Check): Build the actual subtype of the LHS for a view conversion of a constrained object. Diff: --- gcc/ada/checks.adb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 8e6fba46b82e..6f25f23f99a3 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -1551,8 +1551,9 @@ package body Checks is end if; -- If an assignment target is present, then we need to generate the - -- actual subtype if the target is a parameter or aliased object with - -- an unconstrained nominal subtype. + -- actual subtype if the target is a parameter, or a view conversion + -- of a constrained object, or an aliased object with unconstrained + -- nominal subtype. -- Ada 2005 (AI-363): For Ada 2005, we limit the building of the actual -- subtype to the parameter and dereference cases, since other aliased @@ -1561,6 +1562,10 @@ package body Checks is if Present (Lhs) and then (Present (Param_Entity (Lhs)) + or else (not Is_Constrained (T_Typ) + and then Is_View_Conversion (Lhs) + and then + Is_Constrained (Etype (Expression (Lhs)))) or else (Ada_Version < Ada_2005 and then not Is_Constrained (T_Typ) and then Is_Aliased_View (Lhs)
