From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22109 invoked by alias); 22 Jun 2010 09:02:41 -0000 Received: (qmail 22081 invoked by uid 22791); 22 Jun 2010 09:02:36 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 09:02:30 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 2B88CCB0281; Tue, 22 Jun 2010 11:02:32 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c5nI6rHZumdq; Tue, 22 Jun 2010 11:02:32 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 19CAACB024F; Tue, 22 Jun 2010 11:02:32 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 10CEBD9B31; Tue, 22 Jun 2010 11:02:32 +0200 (CEST) Date: Tue, 22 Jun 2010 09:41:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Inherited interface operations hidden by local declaration Message-ID: <20100622090231.GA4799@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="r5Pyd7+fXNt84Ff3" Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2010-06/txt/msg02130.txt.bz2 --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1462 When compiling a type extension with progenitors, we create local symbols for the entries in secondary tables. For each interface primitive we locate the operation that implements the primitive, or else the inherited abstract operation that must eventually be overridden. This abstract operation is normally introduced in the current scope, but it may be hidden because of a local non-overloadable declaration. This patch adds a search through the primitive operations of the type extension to locate the desired inherited interface operation. This prevents crashes on programs where the extension fails to implement the interface operation. Compiling crash.adb must yield: crash.adb:7:04: interface subprogram "p" must be overridden --- procedure Crash is package P is type A_Type is limited interface; procedure P (P : in out A_Type) is abstract; end P; protected type B_Type is new P.A_Type with end; protected body B_Type is end; begin null; end Crash; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-22 Ed Schonberg * sem_ch3.adb (Add_Internal_Interface_Entities): If Find_Primitive_Covering_Interface does not find the operation, it may be because of a name conflict between the inherited operation and a local non-overloadable name. In that case look for the operation among the primitive operations of the type. This search must succeed regardless of visibility. --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 1623 Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 161141) +++ sem_ch3.adb (working copy) @@ -1551,7 +1551,34 @@ package body Sem_Ch3 is (Tagged_Type => Tagged_Type, Iface_Prim => Iface_Prim); - pragma Assert (Present (Prim)); + if No (Prim) then + + -- In some are cases, a name conflict may have + -- kept the operation completely hidden. Look for + -- it in the list of primitive operations of the + -- type. + + declare + El : Elmt_Id := + First_Elmt (Primitive_Operations (Tagged_Type)); + begin + while Present (El) loop + Prim := Node (El); + if Is_Subprogram (Prim) + and then Alias (Prim) = Iface_Prim + then + exit; + end if; + Next_Elmt (El); + end loop; + end; + end if; + + if No (Prim) then + -- If the operation was not explicitly overridden, it + -- should have been inherited as an abstract operation. + raise Program_Error; + end if; Derive_Subprogram (New_Subp => New_Subp, --r5Pyd7+fXNt84Ff3--