As specified in AI12-0170, calls to abstract subprograms within pre-
and postcondition expressions of an abstract subprogram of type T
are allowed in some cases, and references to a formal parameter of
the controlling type are reinterpreted as though they had a (notional)
nonabstract type NT that is a formal derived type whose ancestor type
is T. The compiler was properly allowing such abstract calls, but was
also allowing cases that are still illegal, such as when the abstract
call within the aspect is tag-indeterminate, and such a call is now
properly rejected.

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

gcc/ada/

        * sem_disp.adb (Check_Dispatching_Context): When the enclosing
        subprogram is abstract, bypass early return if the call is
        tag-indeterminate, to continue with the later error checking.
diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -575,12 +575,16 @@ package body Sem_Disp is
             --  Similarly, if this is a pre/postcondition for an abstract
             --  subprogram, it may call another abstract function which is
             --  a primitive of an abstract type. The call is non-dispatching
-            --  but will be legal in overridings of the operation.
+            --  but will be legal in overridings of the operation. However,
+            --  if the call is tag-indeterminate we want to continue with
+            --  with the error checking below, as this case is illegal even
+            --  for abstract subprograms (see AI12-0170).
 
             elsif (Is_Subprogram (Scop)
                     or else Chars (Scop) = Name_Postcondition)
               and then
-                (Is_Abstract_Subprogram (Scop)
+                ((Is_Abstract_Subprogram (Scop)
+                   and then not Is_Tag_Indeterminate (N))
                   or else
                     (Nkind (Parent (Scop)) = N_Procedure_Specification
                       and then Null_Present (Parent (Scop))))


Reply via email to