a component association for component X has a boc, then X is covered in the
aggregate even if there is not default value for X in the type declaration, and
X has to be default-initialized. If the aggregate also has an others clause, X
is not covered by it.

The following must compile quietly in gnat05 mode:

procedure P is
   type R is record
      X : Integer;
      Y : Boolean;
   end record;
   Z : R;
begin
   Z := (X => <>, others => True);
end P;

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

2011-10-13  Ed Schonberg  <schonb...@adacore.com>

        * sem_aggr.adb (Resolve_Record_Aggregate): If a component
        association for component X has a box, then X is covered in the
        aggregate even if there is not default value for X in the type
        declaration, and X has to be default-initialized.

Index: sem_aggr.adb
===================================================================
--- sem_aggr.adb        (revision 179894)
+++ sem_aggr.adb        (working copy)
@@ -3121,6 +3121,13 @@
 
                         Expr := New_Copy_Tree (Expression (Parent (Compon)));
 
+                        --  Component may have no default, in which case the
+                        --  expression is empty and the component is default-
+                        --  initialized, but an association for the component
+                        --  exists, and it is not covered by an others clause.
+
+                        return Expr;
+
                      else
                         if Present (Next (Selector_Name)) then
                            Expr := New_Copy_Tree (Expression (Assoc));

Reply via email to