This patch allows the renaming and subsequent instantiation of generic subprograms that are marked Intrinsic, such as the predefined units Unchecked_Conversion and Unchecked_Deallocation.
The following must execute quietly: gnatmake -q -gnatws uncrename.adb uncrename --- with Mumble; with Dumble; procedure UncRename is function Cast is new Mumble (Boolean, Integer); X : Boolean := True; Y : Integer := Cast (X); type A is access all Integer; procedure Free is new Dumble (Integer, A); Z : A := new Integer; begin Free (Z); end UncRename; --- with Ada.Unchecked_Conversion; generic function Mumble renames Ada.Unchecked_Conversion; --- with Ada.Unchecked_Deallocation; generic procedure Dumble renames Ada.Unchecked_Deallocation; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-07-17 Ed Schonberg <schonb...@adacore.com> * sem_ch8.adb (Analyze_Generic_Renaming): For generic subprograms, propagate intrinsic flag to renamed entity, to allow e.g. renaming of Unchecked_Conversion. * sem_ch3.adb (Analyze_Declarations): Do not analyze contracts if the declaration has errors.
Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 212728) +++ sem_ch3.adb (working copy) @@ -2366,11 +2366,14 @@ -- Analyze the contracts of subprogram declarations, subprogram bodies -- and variables now due to the delayed visibility requirements of their - -- aspects. + -- aspects. Skip analysis if the declaration already has an error. Decl := First (L); while Present (Decl) loop - if Nkind (Decl) = N_Object_Declaration then + if Error_Posted (Decl) then + null; + + elsif Nkind (Decl) = N_Object_Declaration then Analyze_Object_Contract (Defining_Entity (Decl)); elsif Nkind_In (Decl, N_Abstract_Subprogram_Declaration, Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 212726) +++ sem_ch8.adb (working copy) @@ -706,6 +706,14 @@ Error_Msg_N ("within its scope, generic denotes its instance", N); end if; + -- For subprograms, propagate the Intrinsic flag, to allow, e.g. + -- renamings and subsequent instantiations of Unchecked_Conversion. + + if Ekind_In (Old_P, E_Generic_Function, E_Generic_Procedure) then + Set_Is_Intrinsic_Subprogram + (New_P, Is_Intrinsic_Subprogram (Old_P)); + end if; + Check_Library_Unit_Renaming (N, Old_P); end if;