Compiler rejects an equality operation on a record type when the nominal
subtype of a component is a constrained subtype of an Unchecked_Union
type, and that subtype is declared outside of the enclosing record
declaration.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * exp_ch4.adb (Unconstrained_UU_In_Component_Declaration): A
        component declaration whose subtype indication is an entity name
        without an explicit constraint is an Unchecked_Union type only
        if the entity has an unconstrained nominal subtype (record type
        or private type) whose parent type is an Unchecked_Union.
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -8143,11 +8143,16 @@ package body Exp_Ch4 is
             Sindic : constant Node_Id :=
                        Subtype_Indication (Component_Definition (N));
          begin
-            --  Unconstrained nominal type. In the case of a constraint
-            --  present, the node kind would have been N_Subtype_Indication.
+            --  If the component declaration includes a subtype indication
+            --  it is not an unchecked_union. Otherwise verify that it carries
+            --  the Unchecked_Union flag and is either a record or a private
+            --  type. A Record_Subtype declared elsewhere does not qualify,
+            --  even if its parent type carries the flag.
 
             return Nkind (Sindic) in N_Expanded_Name | N_Identifier
-              and then Is_Unchecked_Union (Base_Type (Etype (Sindic)));
+              and then Is_Unchecked_Union (Base_Type (Etype (Sindic)))
+              and then (Ekind (Entity (Sindic)) in
+                         E_Private_Type | E_Record_Type);
          end Unconstrained_UU_In_Component_Declaration;
 
          -----------------------------------------


Reply via email to