]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Allow component clauses for certain record components with discriminants
authorRonan Desplanques <desplanques@adacore.com>
Mon, 24 Nov 2025 08:55:56 +0000 (09:55 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:12 +0000 (11:57 +0100)
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.

gcc/ada/freeze.adb

index fc39cc7b9da1b60d03371006d18d604f5b8c75da..7f5a043cca9e5495884ef9410371505ce75e9623 100644 (file)
@@ -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;