From: Ronan Desplanques <[email protected]>

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.

Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed 
on master.

---
 gcc/ada/freeze.adb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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;
 
-- 
2.51.0

Reply via email to