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] |
This patch adds a warning on certain occurrences of Subprogram'Access that could cause an access-before-elaboration error. The following example should give a warning when compiled with the -gnatw.f switch: % gcc -c -gnatw.f -gnatwe elab_acc.adb elab_acc.ads:4:31: warning: Access attribute of "F" before body seen elab_acc.ads:4:31: warning: possible Program_Error on later references % package Elab_Acc is function F return Integer; type Funcy is access function return Integer; F_Ptr : constant Funcy := F'Access; -- Calls to F_Ptr.all before F's body can cause an -- access-before-elaboration error. end Elab_Acc; package body Elab_Acc is function F return Integer is begin return 123; end F; end Elab_Acc; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-01-07 Bob Duff <duff@adacore.com> * sem_elab.adb (Check_Internal_Call_Continue): Give a warning for P'Access, where P is a subprogram in the same package as the P'Access, and the P'Access is evaluated at elaboration time, and occurs before the body of P. For example, "X : T := P'Access;" would allow a subsequent call to X.all to be an access-before-elaboration error; hence the warning. This warning is enabled by the -gnatw.f switch. * opt.ads (Warn_On_Elab_Access): New flag for warning switch. * warnsw.adb (Set_Dot_Warning_Switch): Set Warn_On_Elab_Access. * gnat_ugn.texi: Document the new warning.
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] |