diff mbox

[Ada] Inherited subprograms may be both abstract and need overriding

Message ID 20110805134704.GA5571@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 5, 2011, 1:47 p.m. UTC
AI05-0028 indicates that an inherited operation can be abstract, even if it
is overridden in a currently non-visible private part, and also require
overriding when the derived type is non-abstract. GNAT has always iplemented
this properly. This patch improves on the error message when this error is
encountered, by indicating that the overriding subprogram is not visible and
therefore not inherited.

Compiling r.ads below in Ada2005 mode must yield:

   r.ads:3:09: type must be declared abstract or "Op" overridden
   r.ads:3:09: "Op" has been inherited at line 3
   r.ads:3:09: "Op" has been inherited at q.ads:3
   r.ads:3:09: "Op" subprogram at q.ads:7 is not visible

package P is
   type I is interface;
   procedure Op (X : I) is abstract;
end P;
---
with P;
package Q is
   type T is abstract new P.I with private;
   -- Op inherited here.
private
   type T is new P.I with null record;
   procedure Op (X : T) is null;
end Q;
---
with Q;
package R is
   type T2 is new Q.T with null record;
   -- Legal? (No.) 
end R;

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

2011-08-05  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb: (Check_Private_Overriding): better error message,
	suggested by AI95-0068.
diff mbox

Patch

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 177431)
+++ sem_ch3.adb	(working copy)
@@ -9118,9 +9118,21 @@ 
                            end loop;
 
                            Error_Msg_Sloc := Sloc (E);
-                           Error_Msg_NE
-                             ("\& has been inherited from subprogram #",
+
+                           --  AI05-0068: report if there is an overriding
+                           --  non-abstract subprogram that is invisible.
+                           if Is_Hidden (E)
+                             and then not Is_Abstract_Subprogram (E)
+                           then
+                              Error_Msg_NE
+                             ("\& subprogram# is not visible",
                               T, Subp);
+
+                           else
+                              Error_Msg_NE
+                                ("\& has been inherited from subprogram #",
+                                 T, Subp);
+                           end if;
                         end;
                      end if;
                   end if;