From patchwork Mon Jun 21 13:45:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 74B1CB7D80 for ; Mon, 21 Jun 2010 23:45:16 +1000 (EST) Received: (qmail 21556 invoked by alias); 21 Jun 2010 13:45:15 -0000 Received: (qmail 21545 invoked by uid 22791); 21 Jun 2010 13:45:14 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL, BAYES_40, 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; Mon, 21 Jun 2010 13:45:08 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B807929001F; Mon, 21 Jun 2010 15:45:08 +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 zGNznZyvB59A; Mon, 21 Jun 2010 15:45:08 +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 98CD4290009; Mon, 21 Jun 2010 15:45:08 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 906D0D9A01; Mon, 21 Jun 2010 15:45:08 +0200 (CEST) Date: Mon, 21 Jun 2010 15:45:08 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Rederivation of interface primitives Message-ID: <20100621134508.GA940@adacore.com> Mime-Version: 1.0 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org When a private extension is completed by a full declaration, a visible primitive operation of the parent type will be derived twice. The derivation produced for the full type declaration must be ignored so that the one associated with the visible partial view is available to clients. This patch extends the corresponding check to the case where the parent type is an interface type. The following must compile quietly: gcc -c -gnat05 proxy.adb --- with Pere, Fils; package Proxy is type T_Proxy is new Pere.T_Pere with private; overriding function Action_Pere (This : in T_Proxy) return Boolean; private type T_Proxy is new Pere.T_Pere with record Un_Fils : Fils.T_Fils_Class_Access; end record; end Proxy; --- package body Proxy is use Fils; function Action_Pere (This : in T_Proxy) return Boolean is begin return This.Un_Fils.Action_pere; end Action_Pere; end Proxy; --- with Pere; package Fils is type T_Fils is abstract new Pere.T_Pere with private; type T_Fils_Class_Access is access all T_Fils'Class; function Action_Fils (This : in T_Fils) return Boolean; private type T_Fils is abstract new Pere.T_Pere with null record; end Fils; --- package body Fils is function Action_Fils (This : in T_Fils) return Boolean is begin return T_Fils'Class (This).Action_Pere; end Action_Fils; end Fils; --- package Pere is type T_Pere is limited interface; function Action_Pere (This : in T_Pere) return Boolean is abstract; end Pere; --- Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-21 Ed Schonberg * sem_ch6.adb (New_Overloaded_Entity): If the new entity is a rederivation associated with a full declaration in a private part, and there is a partial view that derives the same parent subprogram, the new entity does not become visible. This check must be applied to interface operations as well. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 161073) +++ sem_ch6.adb (working copy) @@ -7526,9 +7526,11 @@ package body Sem_Ch6 is -- E exists and is overloadable else - -- Ada 2005 (AI-251): Derivation of abstract interface primitives - -- need no check against the homonym chain. They are directly added - -- to the list of primitive operations of Derived_Type. + -- Ada 2005 (AI-251): Derivation of abstract interface primitives. + -- They are directly added to the list of primitive operations of + -- Derived_Type, unless this is a rederivation in the private part + -- of an operation that was already derived in the visible part of + -- the current package. if Ada_Version >= Ada_05 and then Present (Derived_Type) @@ -7536,7 +7538,16 @@ package body Sem_Ch6 is and then Present (Find_Dispatching_Type (Alias (S))) and then Is_Interface (Find_Dispatching_Type (Alias (S))) then - goto Add_New_Entity; + if Type_Conformant (E, S) + and then Is_Package_Or_Generic_Package (Current_Scope) + and then In_Private_Part (Current_Scope) + and then Parent (E) /= Parent (S) + and then Alias (E) = Alias (S) + then + Check_Operation_From_Private_View (S, E); + else + goto Add_New_Entity; + end if; end if; Check_Synchronized_Overriding (S, Overridden_Subp);