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 incorrect handling of interfaces


Tested on i686-linux, committed on trunk.

This patch introduces a guard against incorrect flagging of subprograms
inherited from an interface ancestor by another interface in the context
of an instance as 'late'.
--
package P1 is
   type I1 is interface;
end P1;
--
with P1;
generic
   type Element is abstract new P1.I1 with private;
package G1 is
   type Dummy is null record;
end G1;
--
with P1;
package P2 is
   type I2 is interface and P1.I1;
end P2;
--
with G1;
with P2;
package P3 is
   package Inst is new G1 (P2.I2);
end P3;
--
Compilation:
  gcc -c -gnat05 p3.ads
--
Output:
  This compilation should not produce errors or warnings.

Late overriding of primitives covering abstract interface subprograms was
unsupported. After this patch, gnat.dg/late_overriding.adb compiles without
errors.

If a formal abstract subprogram has a parameter whose type is a formal
interface type, it is not a primitive operation and checks on its
placement do not apply.
See gnat.dg/specs/gen_interface.ads

Abstract interface primitives must be declared in the package containing
such type declaration. After this patch the compiler reports an error
if such rule is not fulfilled. For example:
--
package Pkg is
  type Iface is interface;
end Pkg;
--
package Pkg.Child is
  procedure Test_1 (O : Iface) is abstract;
  procedure Test_2 (O : access Iface) is abstract;
  function  Test_3 return Iface is abstract;
--
  procedure Test_4 (O : Iface) is null;
  procedure Test_5 (O : access Iface) is null;
end Pkg.Child;
--
Command: gcc -c pkg-child.ads
Output:
pkg-child.ads:3:13: declaration of "Test_1" is too late
pkg-child.ads:3:13: spec should appear immediately after declaration of "Iface"
pkg-child.ads:4:13: declaration of "Test_2" is too late
pkg-child.ads:4:13: spec should appear immediately after declaration of "Iface"
pkg-child.ads:5:13: declaration of "Test_3" is too late
pkg-child.ads:5:13: spec should appear immediately after declaration of "Iface"
pkg-child.ads:7:13: declaration of "Test_4" is too late
pkg-child.ads:7:13: spec should appear immediately after declaration of "Iface"
pkg-child.ads:8:13: declaration of "Test_5" is too late
pkg-child.ads:8:13: spec should appear immediately after declaration of "Iface"

2006-10-31  Hristian Kirtchev  <kirtchev@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Javier Miranda  <miranda@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>

	* sem_disp.adb (Check_Dispatching_Operation): Do not flag subprograms
	inherited from an interface ancestor by another interface in the
	context of an instance as 'late'.
	(Is_Tag_Indeterminate, Propagate_Tag): Handle properly the dereference
	of a call to a function that dispatches on access result.
	(Check_Dispatching_Operation): In case of late overriding of a primitive
	that covers abstract interface subprograms we register it in all the
	secondary dispatch tables associated with abstract interfaces.
	(Check_Dispatching_Call): Add check that a dispatching call is not made
	to a function with a controlling result of a limited type. This is a
	current implementation restriction.
	(Check_Controlling_Formal): Remove bogus checks for E.2.2(14).
	(Check_Dispatching_Operation): Do no emit a warning if the controlling
	argument is an interface type that is a generic formal.
	(Is_Interface_Subprogram): Removed.
	(Check_Dispatching_Operation): If the subprogram is not a dispatching
	operation, check the formals to handle the case in which it is
	associated with an abstract interface type.

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]