Function declared immediately within a protected body is a not a
protected function; the exact definition is RM 9.5.1(1): "A protected
subprogram is a subprogram declared immediately within a protected
definition."

Consequently, functions declared immediately within a protected body are
not volatile.

This fix primarily affects SPARK legality checking; for compilation it
only affects a warning about infinite loops.

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

gcc/ada/

        * sem_util.adb (Is_Volatile_Function): Follow the exact wording
        of SPARK (regarding volatile functions) and Ada (regarding
        protected functions).
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -21105,9 +21105,11 @@ package body Sem_Util is
    begin
       pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
 
-      --  A function declared within a protected type is volatile
+      --  A protected function is volatile
 
-      if Is_Protected_Type (Scope (Func_Id)) then
+      if Nkind (Parent (Unit_Declaration_Node (Func_Id))) =
+           N_Protected_Definition
+      then
          return True;
 
       --  An instance of Ada.Unchecked_Conversion is a volatile function if


Reply via email to