public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Inherited subprograms may be both abstract and need overriding
@ 2011-08-05 13:57 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-08-05 13:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1159 bytes --]

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-05 13:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-05 13:57 [Ada] Inherited subprograms may be both abstract and need overriding Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).