[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Mon, 27 Jan 2014 16:58:19 +0000 (17:58 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 27 Jan 2014 16:58:19 +0000 (17:58 +0100)
2014-01-27  Robert Dewar  <dewar@adacore.com>

* sem_res.adb (Resolve_Comparison_Op): Add type name/location
to unordered msg.
(Resolve_Range): Add type name/location to unordered msg.

2014-01-27  Claire Dross  <dross@adacore.com>

* a-cofove.adb/s (Copy): Add precondition so that Copy (Source,
Capacity) is only called with Capacity >= Length (Source) and
Capacity in Capacity_Range.
* a-cfdlli.adb/s, a-cfhase.adb/s, a-cfhama.adb/s, a-cforse.adb/s,
a-cforma.adb/s (Copy): Add precondition so that Copy (Source, Capacity)
is only called with Capacity >= Source.Capacity. Raise Capacity_Error
in the code is this is not the case.

2014-01-27  Thomas Quinot  <quinot@adacore.com>

* sem_ch4.adb (Analyze_Selected_Component): Fix handling of
selected component in an instance where the component of the
actual is not visibile at instantiation.

From-SVN: r207146

15 files changed:
gcc/ada/ChangeLog
gcc/ada/a-cfdlli.adb
gcc/ada/a-cfdlli.ads
gcc/ada/a-cfhama.adb
gcc/ada/a-cfhama.ads
gcc/ada/a-cfhase.adb
gcc/ada/a-cfhase.ads
gcc/ada/a-cforma.adb
gcc/ada/a-cforma.ads
gcc/ada/a-cforse.adb
gcc/ada/a-cforse.ads
gcc/ada/a-cofove.adb
gcc/ada/a-cofove.ads
gcc/ada/sem_ch4.adb
gcc/ada/sem_res.adb

index a57ac289ef9b35d592158ff7eb8e4a6ad60ed75d..237c3e0aa0a94e5b598474b7dc2f47e5893ace8f 100644 (file)
@@ -1,3 +1,25 @@
+2014-01-27  Robert Dewar  <dewar@adacore.com>
+
+       * sem_res.adb (Resolve_Comparison_Op): Add type name/location
+       to unordered msg.
+       (Resolve_Range): Add type name/location to unordered msg.
+
+2014-01-27  Claire Dross  <dross@adacore.com>
+
+       * a-cofove.adb/s (Copy): Add precondition so that Copy (Source,
+       Capacity) is only called with Capacity >= Length (Source) and
+       Capacity in Capacity_Range.
+       * a-cfdlli.adb/s, a-cfhase.adb/s, a-cfhama.adb/s, a-cforse.adb/s,
+       a-cforma.adb/s (Copy): Add precondition so that Copy (Source, Capacity)
+       is only called with Capacity >= Source.Capacity. Raise Capacity_Error
+       in the code is this is not the case.
+
+2014-01-27  Thomas Quinot  <quinot@adacore.com>
+
+       * sem_ch4.adb (Analyze_Selected_Component): Fix handling of
+       selected component in an instance where the component of the
+       actual is not visibile at instantiation.
+
 2014-01-27  Ed Schonberg  <schonberg@adacore.com>
 
        * sem_ch6.adb: sem_ch6.adb (Set_Actual_Subtypes): If the type
index 34668bdd2d513c92e9b5dbdd02e49a890d0a2c15..982c1b7d2f724f87d4795a2223fc252438fb4ff4 100644 (file)
@@ -229,6 +229,10 @@ package body Ada.Containers.Formal_Doubly_Linked_Lists is
       P : List (C);
 
    begin
+      if 0 < Capacity and then Capacity < Source.Capacity then
+         raise Capacity_Error;
+      end if;
+
       N := 1;
       while N <= Source.Capacity loop
          P.Nodes (N).Prev := Source.Nodes (N).Prev;
index 660eb18e302abb7bc3921a950f9c2f15fd64d3a8..54f1886d297b235e9469c86dc89a724bece756e5 100644 (file)
@@ -84,7 +84,8 @@ package Ada.Containers.Formal_Doubly_Linked_Lists is
    procedure Assign (Target : in out List; Source : List) with
      Pre => Target.Capacity >= Length (Source);
 
-   function Copy (Source : List; Capacity : Count_Type := 0) return List;
+   function Copy (Source : List; Capacity : Count_Type := 0) return List with
+     Pre => Capacity = 0 or else Capacity >= Source.Capacity;
 
    function Element
      (Container : List;
index 3ab4af23e786972198e28aaef37781b3cd5cce82..938423894c205e8f819ed96da3a6e067b79fb93d 100644 (file)
@@ -207,6 +207,10 @@ package body Ada.Containers.Formal_Hashed_Maps is
       Cu     : Cursor;
 
    begin
+      if 0 < Capacity and then Capacity < Source.Capacity then
+         raise Capacity_Error;
+      end if;
+
       Target.Length := Source.Length;
       Target.Free := Source.Free;
 
index 5366655753eb34ba6a7e2bafd75df69b2558f919..71eed2b0e4db81cc23eae08973e4d08188f3cdea 100644 (file)
@@ -100,7 +100,7 @@ package Ada.Containers.Formal_Hashed_Maps is
      (Source   : Map;
       Capacity : Count_Type := 0) return Map
    with
-     Pre => Capacity >= Source.Capacity;
+     Pre => Capacity = 0 or else Capacity >= Source.Capacity;
    --  Copy returns a container stricty equal to Source. It must have
    --  the same cursors associated with each element. Therefore:
    --  - capacity=0 means use container.capacity as capacity of target
index 451ec32a8861d88aa265b2f0ab126acdc7ae749d..96f0d05c057210bd972ffee6eca78c6735f5a921 100644 (file)
@@ -233,6 +233,10 @@ package body Ada.Containers.Formal_Hashed_Sets is
       Cu     : Cursor;
 
    begin
+      if 0 < Capacity and then Capacity < Source.Capacity then
+         raise Capacity_Error;
+      end if;
+
       Target.Length := Source.Length;
       Target.Free := Source.Free;
 
index d470e1b8a9f982d2ca6662e5aa1149a5c043160e..a3fc63dc03679a52893a50383ac53706f3915c03 100644 (file)
@@ -106,7 +106,7 @@ package Ada.Containers.Formal_Hashed_Sets is
      (Source   : Set;
       Capacity : Count_Type := 0) return Set
    with
-     Pre => Capacity >= Source.Capacity;
+     Pre => Capacity = 0 or else Capacity >= Source.Capacity;
 
    function Element
      (Container : Set;
index ac763918283042f1a283ce15651c4f2252acf5d4..33cd101badc2e945271ed7ef739393aa8034c978 100644 (file)
@@ -283,6 +283,10 @@ package body Ada.Containers.Formal_Ordered_Maps is
       N    : Count_Type;
 
    begin
+      if 0 < Capacity and then Capacity < Source.Capacity then
+         raise Capacity_Error;
+      end if;
+
       return Target : Map (Count_Type'Max (Source.Capacity, Capacity)) do
          if Length (Source) > 0 then
             Target.Length := Source.Length;
index 00cd3989d52c618df610e5e5cc20392061309f92..a9426764560ac17bd5433282004eacb276add4bf 100644 (file)
@@ -92,7 +92,7 @@ package Ada.Containers.Formal_Ordered_Maps is
      Pre => Target.Capacity >= Length (Source);
 
    function Copy (Source : Map; Capacity : Count_Type := 0) return Map with
-     Pre => Capacity >= Source.Capacity;
+     Pre => Capacity = 0 or else Capacity >= Source.Capacity;
 
    function Key (Container : Map; Position : Cursor) return Key_Type with
      Pre => Has_Element (Container, Position);
index 22e92220b9d942cfceddc647a928ad6121963cef..1b202f03b1bf45dd50fc5bff13c673c68b96fb08 100644 (file)
@@ -320,6 +320,10 @@ package body Ada.Containers.Formal_Ordered_Sets is
       Target : Set (Count_Type'Max (Source.Capacity, Capacity));
 
    begin
+      if 0 < Capacity and then Capacity < Source.Capacity then
+         raise Capacity_Error;
+      end if;
+
       if Length (Source) > 0 then
          Target.Length := Source.Length;
          Target.Root   := Source.Root;
index 0116e8f2791188963b1d2428ee3b6f5b76c5005b..e935be5e457bf2ee5b19a37f6dd1248ffb92ea68 100644 (file)
@@ -94,7 +94,7 @@ package Ada.Containers.Formal_Ordered_Sets is
      Pre => Target.Capacity >= Length (Source);
 
    function Copy (Source : Set; Capacity : Count_Type := 0) return Set with
-     Pre => Capacity >= Source.Capacity;
+     Pre => Capacity = 0 or else Capacity >= Source.Capacity;
 
    function Element
      (Container : Set;
index 6789f712af8505da6143daa493537eb5aa47dde2..93372e1c5cb9cfb9db22fbd7b2cf0decf072ae77 100644 (file)
@@ -301,10 +301,10 @@ package body Ada.Containers.Formal_Vectors is
    begin
       if Capacity = 0 then
          C := LS;
-      elsif Capacity >= LS then
+      elsif Capacity >= LS and then Capacity in Capacity_Range then
          C := Capacity;
       else
-         raise Constraint_Error;
+         raise Capacity_Error;
       end if;
 
       return Target : Vector (C) do
index 2c451fb8ebcdb79be708a2962f820590e9498576..313165c49c662c24f568e13588406960fdc7c91e 100644 (file)
@@ -125,7 +125,7 @@ package Ada.Containers.Formal_Vectors is
      (Source   : Vector;
       Capacity : Count_Type := 0) return Vector
    with
-     Pre => Length (Source) <= Capacity;
+     Pre => Length (Source) <= Capacity and then Capacity in Capacity_Range;
 
    function To_Cursor
      (Container : Vector;
index 1512a7ad240d620b22a516a76557061eb7ca60db..51e7f090b19d6cb576c716be5711f8a799001e28 100644 (file)
@@ -3943,6 +3943,7 @@ package body Sem_Ch4 is
       --  searches have failed. When the match is found (it always will be),
       --  the Etype of both N and Sel are set from this component, and the
       --  entity of Sel is set to reference this component.
+      --  ??? no longer true that a match is found ???
 
       function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
       --  It is known that the parent of N denotes a subprogram call. Comp
@@ -3971,9 +3972,7 @@ package body Sem_Ch4 is
             Next_Component (Comp);
          end loop;
 
-         --  This must succeed because code was legal in the generic
-
-         raise Program_Error;
+         --  Need comment on what is going on when we fall through ???
       end Find_Component_In_Instance;
 
       ------------------------------
@@ -4607,27 +4606,47 @@ package body Sem_Ch4 is
             Analyze_Selected_Component (N);
             return;
 
-         --  Similarly, if this is the actual for a formal derived type, the
-         --  component inherited from the generic parent may not be visible
-         --  in the actual, but the selected component is legal.
+         --  Similarly, if this is the actual for a formal derived type, or
+         --  a derived type thereof, the component inherited from the generic
+         --  parent may not be visible in the actual, but the selected
+         --  component is legal. Climb up the derivation chain of the generic
+         --  parent type until we find the proper ancestor type.
 
-         elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
-           and then Is_Generic_Actual_Type (Prefix_Type)
-           and then Present (Full_View (Prefix_Type))
-         then
-            Find_Component_In_Instance
-              (Generic_Parent_Type (Parent (Prefix_Type)));
-            return;
+         elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
+            declare
+               Par : Entity_Id := Prefix_Type;
+            begin
+               --  Climb up derivation chain to generic actual subtype
+
+               while not Is_Generic_Actual_Type (Par) loop
+                  if Ekind (Par) = E_Record_Type then
+                     Par := Parent_Subtype (Par);
+                     exit when No (Par);
+                  else
+                     exit when Par = Etype (Par);
+                     Par := Etype (Par);
+                  end if;
+               end loop;
 
-         --  Finally, the formal and the actual may be private extensions,
-         --  but the generic is declared in a child unit of the parent, and
-         --  an additional step is needed to retrieve the proper scope.
+               if Present (Par) and then Is_Generic_Actual_Type (Par) then
+                  --  Now look for component in ancestor types
 
-         elsif In_Instance
-           and then Present (Parent_Subtype (Etype (Base_Type (Prefix_Type))))
-         then
-            Find_Component_In_Instance
-              (Parent_Subtype (Etype (Base_Type (Prefix_Type))));
+                  Par := Generic_Parent_Type (Declaration_Node (Par));
+                  loop
+                     Find_Component_In_Instance (Par);
+                     exit when Present (Entity (Sel))
+                       or else Par = Etype (Par);
+                     Par := Etype (Par);
+                  end loop;
+               end if;
+            end;
+
+            --  The search above must have eventually succeeded, since the
+            --  selected component was legal in the generic.
+
+            if No (Entity (Sel)) then
+               raise Program_Error;
+            end if;
             return;
 
          --  Component not found, specialize error message when appropriate
index 7e2e55cff7414e7489820b5e1344e3092ba2221a..aff4b47926a63fc44c6797234838fa6e05589454 100644 (file)
@@ -6287,7 +6287,10 @@ package body Sem_Res is
       --  Check comparison on unordered enumeration
 
       if Bad_Unordered_Enumeration_Reference (N, Etype (L)) then
-         Error_Msg_N ("comparison on unordered enumeration type?U?", N);
+         Error_Msg_Sloc := Sloc (Etype (L));
+         Error_Msg_NE
+           ("comparison on unordered enumeration type& declared#?U?",
+            N, Etype (L));
       end if;
 
       --  Evaluate the relation (note we do this after the above check since
@@ -8830,7 +8833,9 @@ package body Sem_Res is
 
         and then not First_Last_Ref
       then
-         Error_Msg ("subrange of unordered enumeration type?U?", Sloc (N));
+         Error_Msg_Sloc := Sloc (Typ);
+         Error_Msg_NE
+           ("subrange of unordered enumeration type& declared#?U?", N, Typ);
       end if;
 
       Check_Unset_Reference (L);