This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Conformance checking in instantiations


Within an instance, a subprogram declaration and the corresponding body may be
fully conformant, but one may use in its profile a formal type while the other
uses a declared subtype of that formal. The routine Same_Generic_Actual is used
to recognize this case and prevent a spurious conformance error or the creation
of two different subprograms, which leads to errors at link time. This patch
makes the check symmetric, so that either the spec or the body may use a
declared subtype of the generic formal.

The following must execute quietly:

   gnatmake -q main

---
with specific_vector;
procedure main is
   sv : specific_vector.Object := (1.0, 2.0, 3.0);
begin
   sv := specific_vector."-"(Right => sv);
end main;
---
with Vector_Types;
generic
   type Vector_Element is digits <>;
   type Vector  is array (Vector_Types.Coordinate) of Vector_Element;
Package Generic_Vector is
   subtype Object is Vector;

   function "-" (Right : Object) return Object;
end Generic_Vector;
---
with Vector_Types;
package body Generic_Vector is

   function "-" (Right : Vector) return Vector is
      Negated_Vector : Vector := (vector_types.X => -Right(vector_types.X),
                                  vector_types.Y => -Right(vector_types.Y),
                                  vector_types.Z => -Right(vector_types.Z) );
   begin
      return Negated_Vector;
   end "-";
end Generic_Vector;
---
with interfaces;
with Vector_Types;
with Generic_Vector;
package Specific_Vector is new
      Generic_Vector(Vector_Element => Interfaces.IEEE_Float_64,
                     Vector         => Vector_Types.Float_Vector_64);
---
with interfaces;
package Vector_Types is
   type Coordinate is (X, Y, Z);
   type Float_Vector_64 is array (Coordinate) of Interfaces.IEEE_Float_64;
end Vector_Types;

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

2014-08-01  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Same_Generic_Actual): Make function symmetric,
	because either type may be a subtype of the other.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]