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] fix handling of object.method notation


Tested on i686-linux, committed on trunk

A prefixed view of a subprogram requires that the object that is the prefix
of the call have the same type as the first parameter of the subprogram,
The first parameter may be declared as a subtype of a class-wide type, and
match an object or formal of the class-wide type. Previous to this patch,
the code required exact matching of subtypes.

See gnat.dg/prefix2.adb

This patch also fixes a hole in conformance checking on prefixed calls. If the
prefix is of an access type and the controlling formal is not, we insert
an implicit dereference on the prefix. However, if the formal is not a
constant, we must verify that the prefix is not an access_to_constant type.

Compiling p.adb in Ada2005 mode must be rejected with the message:

   p.adb:15:04: expect variable in call to "Proc"

procedure P is
   package Pkg is
      type T is tagged null record;
      type Acc is access constant T;
      procedure Proc (X : in out T);
   end Pkg;
	
   package body Pkg is
      procedure Proc (X : in out T) is begin null; end;
   end Pkg;
   use Pkg;
   Obj : aliased T;
   Ptr : Acc := Obj'access;
begin
   Ptr.Proc;
end;

2007-08-14  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch4.adb (Try_Class_Wide_Operation): use base type of first
	parameter to determine whether operation applies to the prefix.
	(Complete_Object_Operation): If actual has an access type and
	controlling formal is not an in_parameter, reject the actual if it is
	an access_to_constant type.
	(Try_Primitive_Operation): If the type of the prefix is a formal tagged
	type, the candidate operations are found in the scope of declaration of
	the type, because the type has no primitive subprograms.
	(Analyze_Selected_Component): If prefix is class-wide, and root type is
	a private extension, only examine visible components before trying to
	analyze as a prefixed call.
	Change Entity_List to Type_To_Use, for better readability.
	(Has_Fixed_Op): Use base type when checking whether the type of an
	operator has a user-defined multiplication/division
	(Check_Arithmetic_Pair): Use Ada 2005 rules to remove ambiguities when
	user-defined operators are available for fixed-point types.

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]