From patchwork Mon Oct 4 13:17:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 66649 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 909F8B70D3 for ; Tue, 5 Oct 2010 00:17:32 +1100 (EST) Received: (qmail 28348 invoked by alias); 4 Oct 2010 13:17:30 -0000 Received: (qmail 28336 invoked by uid 22791); 4 Oct 2010 13:17:29 -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; Mon, 04 Oct 2010 13:17:25 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 5D202CB025E; Mon, 4 Oct 2010 15:17:23 +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 hkW8IVi4AdKF; Mon, 4 Oct 2010 15:17:23 +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 4A69FCB01DD; Mon, 4 Oct 2010 15:17:23 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 2DE3BD9BB4; Mon, 4 Oct 2010 15:17:23 +0200 (CEST) Date: Mon, 4 Oct 2010 15:17:23 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Subprogram renaming and private overriding Message-ID: <20101004131723.GA17852@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 If an inherited operation is overridden in the private part, a client only sees the overridden operation, which may be abstact. A call from a client will invoke the overridding operation, so this is the one that must be used in the renaming. Otherwise the compiler with produce a spurious error if the overridden operation is abstract. The following must compile quietly: gcc -c -gnat05 my_vector.ads --- package My_Interface is type Instance is interface; procedure P (I : in out Instance) is abstract; end My_Interface; --- with My_Interface; package My_Tagged_Type is type Instance is new My_Interface.Instance with private; procedure P (TT : in out Instance) is null; private type Instance is new My_Interface.Instance with null record; end My_Tagged_Type; --- with Ada.Containers.Vectors; with My_Tagged_Type; package My_Vector is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => My_Tagged_Type.Instance, "=" => My_Tagged_Type."="); Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-04 Ed Schonberg * sem_ch8.adb (Analyze_Subprogram_Renaming): If the renamed operation is an overridden inherited operation, the desired operation is the overriding one, which is the alias of the visible one. Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 164906) +++ sem_ch8.adb (working copy) @@ -2100,6 +2100,21 @@ package body Sem_Ch8 is if No (Old_S) then Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual); + -- The visible operation may be an inherited abstract operation that + -- was overridden in the private part, in which case a call will + -- dispatch to the overriding operation. Use the overriding one in + -- the renaming declaration, to prevent spurious errors below. + + if Is_Overloadable (Old_S) + and then Is_Abstract_Subprogram (Old_S) + and then No (DTC_Entity (Old_S)) + and then Present (Alias (Old_S)) + and then not Is_Abstract_Subprogram (Alias (Old_S)) + and then Is_Overriding_Operation (Alias (Old_S)) + then + Old_S := Alias (Old_S); + end if; + -- When the renamed subprogram is overloaded and used as an actual -- of a generic, its entity is set to the first available homonym. -- We must first disambiguate the name, then set the proper entity.