An allocator for a local task in a package declaration will raise Program_Error because the elaboration check on the body will fail. THis patch adds a warning for this case.
Compiling the following must yield: tasking.ads:6:18: warning: cannot activate task before body seen tasking.ads:6:18: warning: Program_Error will be raised at run time --- package Tasking is task type T; type T_Ptr is access T; TP : T_Ptr := new T; TT : T; -- This is OK end Tasking; --- with Text_Io; use Text_IO; package body Tasking is task body T is begin Put_Line ("Activated"); null; end T; end Tasking; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-04 Ed Schonberg <schonb...@adacore.com> * sem_res.adb (Resolve_Allocator): diagnose task allocator that will raise program_error because body has not been seen yet.
Index: sem_res.adb =================================================================== --- sem_res.adb (revision 177356) +++ sem_res.adb (working copy) @@ -4342,6 +4342,21 @@ Set_Is_Static_Coextension (N, False); end if; end if; + + -- Report a simple error: if the designated object is a local task, + -- its body has not been seen yet, and its activation will fail + -- an elaboration check. + + if Is_Task_Type (Designated_Type (Typ)) + and then Scope (Base_Type (Designated_Type (Typ))) = Current_Scope + and then Is_Compilation_Unit (Current_Scope) + and then Ekind (Current_Scope) = E_Package + and then not In_Package_Body (Current_Scope) + then + Error_Msg_N + ("cannot activate task before body seen?", N); + Error_Msg_N ("\Program_Error will be raised at run time", N); + end if; end Resolve_Allocator; ---------------------------