This patch fixes two bugs in the handling of 'access applied to a protected subprogram, when the attribute reference appears within a generic body, and the access type is declared outside of the body. This is now properly rejected. The patch also fixes a bug in the legality check for convention, and removes a spurious error.
Compiling proc.adb must yield the following error messages: proc.odb:15:31: 'Access attribute not allowed in generic body proc.adb:15:31: because access type "Ptr" is declared outside generic unit (RM 3.10.2(32)) proc.adb:15:31: move 'Access to private part, or (Ada 2005) use anonymous access type instead of "Ptr" --- procedure Proc is type Ptr is access protected procedure (P : Integer); generic package Gen is procedure Register (Link : Ptr); protected type Prot is procedure Transmit (X : Integer); end Prot; end; package body Gen is procedure Register (Link : Ptr) is begin null; end; protected body Prot is procedure Transmit (X : Integer) is begin Register (Transmit'access); -- ERROR end; end; end; begin null; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-01 Ed Schonberg <schonb...@adacore.com> * sem_attr.adb (Analyze_Attribute, case 'Access): handle properly named access to protected subprograms in generic bodies. * sem_ch6.adb (Analyze_Subprogram_Declaration): If the context is a protected type, indicate that the convention of the subprogram is Convention_Protected, because it may be used in subsequent declarations within the protected declaration.
Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 177001) +++ sem_attr.adb (working copy) @@ -7837,14 +7837,16 @@ package body Sem_Attr is if Ekind_In (Btyp, E_Access_Subprogram_Type, E_Anonymous_Access_Subprogram_Type, + E_Access_Protected_Subprogram_Type, E_Anonymous_Access_Protected_Subprogram_Type) then -- Deal with convention mismatch - if Convention (Btyp) /= Convention (Entity (P)) then + if Convention (Designated_Type (Btyp)) /= + Convention (Entity (P)) + then Error_Msg_FE ("subprogram & has wrong convention", P, Entity (P)); - Error_Msg_FE ("\does not match convention of access type &", P, Btyp); Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 176998) +++ sem_ch6.adb (working copy) @@ -2929,6 +2929,14 @@ package body Sem_Ch6 is Write_Eol; end if; + if Is_Protected_Type (Current_Scope) then + + -- Indicate that this is a protected operation, because it may be + -- used in subsequent declarations within the protected type. + + Set_Convention (Designator, Convention_Protected); + end if; + List_Inherited_Pre_Post_Aspects (Designator); Analyze_Aspect_Specifications (N, Designator, Aspect_Specifications (N)); end Analyze_Subprogram_Declaration;