The compiler gave a wrong error about "must override" in the following
case.  A private type is completed with a derived type that inherits a
must-override function. Outside that package, a type extension of the
private type is declared.  The function on that type extension is not
visible, and is not must-override, so should not be in error. Indeed, it
cannot be overridden.  This patch fixes the bug, suppressing that error
message.

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

2019-12-18  Bob Duff  <d...@adacore.com>

gcc/ada/

        * sem_ch3.adb (Derive_Subprogram): Do not set the
        Requires_Overriding flag in the above-mentioned case.
--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -15606,7 +15606,8 @@ package body Sem_Ch3 is
          Set_Derived_Name;
 
       --  Otherwise, the type is inheriting a private operation, so enter it
-      --  with a special name so it can't be overridden.
+      --  with a special name so it can't be overridden. See also below, where
+      --  we check for this case, and if so avoid setting Requires_Overriding.
 
       else
          Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
@@ -15786,7 +15787,15 @@ package body Sem_Ch3 is
            or else Is_Abstract_Subprogram (Alias (New_Subp))
          then
             Set_Is_Abstract_Subprogram (New_Subp);
-         else
+
+         --  If the Chars of the new subprogram is different from that of the
+         --  parent's one, it means that we entered it with a special name so
+         --  it can't be overridden (see above). In that case we had better not
+         --  *require* it to be overridden. This is the case where the parent
+         --  type inherited the operation privately, so there's no danger of
+         --  dangling dispatching.
+
+         elsif Chars (New_Subp) = Chars (Alias (New_Subp)) then
             Set_Requires_Overriding (New_Subp);
          end if;
 

Reply via email to