[Ada] Type conformance for access_to_subprogram types
Arnaud Charlet
charlet@adacore.com
Mon Jul 8 08:10:00 GMT 2013
Two anonymous_access_to_subprograsm types are type conformant if the designated
type of one is protected and the other is not. Convention of the designated
types only matters when checking subtype conformance. Previous to this patch,
the compiler failed to recognize that the following declarations are illegal
homonyms:
---
package P is
function F return access procedure (I : Integer);
function F return access protected procedure (I : Integer);
end P;
---
Compiling the above with -gnatc must yield:
p.ads:4:13: "F" conflicts with declaration at line 3
Tested on x86_64-pc-linux-gnu, committed on trunk
2013-07-08 Ed Schonberg <schonberg@adacore.com>
* sem_ch6.adb (Conforming_Types): Anonymous_access_to_subprograsm
types are type conformant if the designated type of one is
protected and the other is not. Convention only matters when
checking subtype conformance.
-------------- next part --------------
Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb (revision 200688)
+++ sem_ch6.adb (working copy)
@@ -2789,11 +2789,11 @@
and then
(Nkind (Original_Node (Spec_Decl)) =
N_Subprogram_Renaming_Declaration
- or else (Present (Corresponding_Body (Spec_Decl))
- and then
- Nkind (Unit_Declaration_Node
- (Corresponding_Body (Spec_Decl))) =
- N_Subprogram_Renaming_Declaration))
+ or else (Present (Corresponding_Body (Spec_Decl))
+ and then
+ Nkind (Unit_Declaration_Node
+ (Corresponding_Body (Spec_Decl))) =
+ N_Subprogram_Renaming_Declaration))
then
Conformant := True;
@@ -7663,13 +7663,16 @@
end if;
-- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
- -- treated recursively because they carry a signature.
+ -- treated recursively because they carry a signature. As far as
+ -- conformance is concerned, convention plays no role, and either
+ -- or both could be access to protected subprograms.
Are_Anonymous_Access_To_Subprogram_Types :=
- Ekind (Type_1) = Ekind (Type_2)
+ Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
+ E_Anonymous_Access_Protected_Subprogram_Type)
and then
- Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
- E_Anonymous_Access_Protected_Subprogram_Type);
+ Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
+ E_Anonymous_Access_Protected_Subprogram_Type);
-- Test anonymous access type case. For this case, static subtype
-- matching is required for mode conformance (RM 6.3.1(15)). We check
More information about the Gcc-patches
mailing list