From: Ronan Desplanques Date: Mon, 24 Nov 2025 08:55:56 +0000 (+0100) Subject: ada: Allow component clauses for certain record components with discriminants X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d24c744d41f7b0cada458d5cde1a50d690d10f2;p=thirdparty%2Fgcc.git ada: Allow component clauses for certain record components with discriminants Before this patch, the compiler rejected record representation clauses when a component has a subtype with a non-static discriminant constraint. This is a somewhat coarse-grained since the size of such a component can be constant relatively to the discriminant. One such case in particular is when the component subtype is an unchecked union. This patch makes the compiler accept the unchecked union case. gcc/ada/ChangeLog: * freeze.adb (Size_Known): Modify rejection condition. --- diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index fc39cc7b9da..7f5a043cca9 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -932,10 +932,15 @@ package body Freeze is elsif Is_Record_Type (T) then -- A subtype of a variant record must not have non-static - -- discriminated components. + -- discriminants that influence the size. We don't do all that we + -- could to determine whether a non-static discriminant value can + -- make the size vary, but we handle the special case of unchecked + -- unions where all objects have the same size (see RM B.3.3 + -- (14/2)). if T /= Base_Type (T) and then not Static_Discriminated_Components (T) + and then not Is_Unchecked_Union (T) then return False;