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 @@ -751,14 +751,22 @@ package body Sem_Disp is elsif Is_Subprogram (Scop) and then not Is_Tag_Indeterminate (N) - and then In_Pre_Post_Condition (Call, Class_Wide_Only => True) + and then + -- The context is an internally built helper or an indirect + -- call wrapper that handles class-wide preconditions + (Present (Class_Preconditions_Subprogram (Scop)) - -- The tagged type associated with the called subprogram must be - -- the same as that of the subprogram with a class-wide aspect. + -- ... or the context is a class-wide pre/postcondition. + or else + (In_Pre_Post_Condition (Call, Class_Wide_Only => True) - and then Is_Dispatching_Operation (Scop) - and then - Find_Dispatching_Type (Subp) = Find_Dispatching_Type (Scop) + -- The tagged type associated with the called + -- subprogram must be the same as that of the + -- subprogram with a class-wide aspect. + + and then Is_Dispatching_Operation (Scop) + and then Find_Dispatching_Type (Subp) + = Find_Dispatching_Type (Scop))) then null;