]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Reject pragma Attach_Handler on procedures in protected bodies
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 31 Jul 2025 15:07:48 +0000 (17:07 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 9 Sep 2025 12:39:53 +0000 (14:39 +0200)
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.

gcc/ada/sem_prag.adb

index e73cdedb4f6a0e7c13acad21994c719686781d57..00b78d9632fbeaeb9137bf4d92eb8c45ec8016b9 100644 (file)
@@ -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.