From: Piotr Trojanek Date: Thu, 31 Jul 2025 15:07:48 +0000 (+0200) Subject: ada: Reject pragma Attach_Handler on procedures in protected bodies X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77db91aae8dd9ce61c01c74bbc3d66cd990a7526;p=thirdparty%2Fgcc.git ada: Reject pragma Attach_Handler on procedures in protected bodies Pragma Attach_Handler and Interrupt_Handler are only legal for procedures declared in protected definition. When given for procedures declared in protected body, they were wrongly accepted and triggered an odd error message from expansion. gcc/ada/ChangeLog: * sem_prag.adb (Check_Interrupt_Or_Attach_Handler): Refine test for protected procedures; fix typo in comment. --- diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index e73cdedb4f6..00b78d9632f 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -7023,12 +7023,14 @@ package body Sem_Prag is Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1); Proc_Scope := Scope (Handler_Proc); - if Ekind (Proc_Scope) /= E_Protected_Type then + if Nkind (Parent (Subprogram_Spec (Handler_Proc))) /= + N_Protected_Definition + then Error_Pragma_Arg ("argument of pragma% must be protected procedure", Arg1); end if; - -- For pragma case (as opposed to access case), check placement. + -- For pragma case (as opposed to aspect case), check placement. -- We don't need to do that for aspects, because we have the -- check that they aspect applies an appropriate procedure.