This patch adds checks to reject illegal overriding indicators that
appear on subprogram declarations in protected bodies, where such
a subprogram cannot override any operation. Fixes ACATS test B831006.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-12  Ed Schonberg  <schonb...@adacore.com>

gcc/ada/

        * sem_ch6.adb (Check_Overriding_Indicatior): Reject an
        overriding indicator on a subprogram declared within a protected
        body.
--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -6515,6 +6515,19 @@ package body Sem_Ch6 is
          return;
       end if;
 
+      --  An overriding indication is illegal on a subprogram declared
+      --  in a protected body, where there is no operation to override.
+
+      if (Must_Override (Spec) or else Must_Not_Override (Spec))
+        and then Is_List_Member (Decl)
+        and then Present (Parent (List_Containing (Decl)))
+        and then Nkind (Parent (List_Containing (Decl))) = N_Protected_Body
+      then
+         Error_Msg_N
+           ("illegal overriding indication in protected body", Decl);
+         return;
+      end if;
+
       --  The overriding operation is type conformant with the overridden one,
       --  but the names of the formals are not required to match. If the names
       --  appear permuted in the overriding operation, this is a possible

Reply via email to