From patchwork Mon Jun 14 13:46:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 55533 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 565DDB7D84 for ; Mon, 14 Jun 2010 23:46:55 +1000 (EST) Received: (qmail 30724 invoked by alias); 14 Jun 2010 13:46:54 -0000 Received: (qmail 30709 invoked by uid 22791); 14 Jun 2010 13:46:53 -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, 14 Jun 2010 13:46:49 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id C656FCB0225; Mon, 14 Jun 2010 15:46:52 +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 99cu9eMjvI-n; Mon, 14 Jun 2010 15:46:52 +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 A87DACB01BA; Mon, 14 Jun 2010 15:46:52 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id CF951D9B31; Mon, 14 Jun 2010 15:46:59 +0200 (CEST) Date: Mon, 14 Jun 2010 15:46:59 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [Ada] Overriding indicator rejected for controlled operation in child unit Message-ID: <20100614134659.GA12650@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 The compiler rejects an overriding indicator on a controlled operation declared within a child unit's private part for a full type that inherits the controlled operation as a hidden operation in its partial view. When checking legality of overriding indicators, the test for whether the overridden subprogram is hidden doesn't apply in general for controlled operations, because those are marked as hidden when inherited by a private extension from a type that declares them in a private part. The problem is that they never become unhidden, even when the full type has visibility of their parent subprogram, as can occur within a child unit. This is corrected by adding a test of whether the parent subprogram of the overridden subprogram is itself hidden, in the specific case where the subprograms are controlled operations. Child package priv_controlled-override.adb must compile quietly with -gnat05: with Ada.Finalization; package Priv_Controlled is type Privately_Controlled is tagged private; private type Privately_Controlled is new Ada.Finalization.Controlled with null record; overriding procedure Finalize (Self : in out Privately_Controlled); end Priv_Controlled; package Priv_Controlled.Override is type Other_Priv_Controlled is new Privately_Controlled with private; private type Other_Priv_Controlled is new Privately_Controlled with null record; overriding procedure Finalize (Self : in out Other_Priv_Controlled); end Priv_Controlled.Override; package body Priv_Controlled.Override is overriding procedure Finalize (Self : in out Other_Priv_Controlled) is begin null; end Finalize; end Priv_Controlled.Override; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-14 Gary Dismukes * sem_ch6.adb (Check_Overriding_Indicator): Add a special check for controlled operations, so that they will be treated as overriding even if the overridden subprogram is marked Is_Hidden, as long as the overridden subprogram's parent subprogram is not hidden. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 160723) +++ sem_ch6.adb (working copy) @@ -4420,8 +4420,24 @@ package body Sem_Ch6 is end; end if; + -- If there is an overridden subprogram, then check that there is not + -- a "not overriding" indicator, and mark the subprogram as overriding. + -- This is not done if the overridden subprogram is marked as hidden, + -- which can occur for the case of inherited controlled operations + -- (see Derive_Subprogram), unless the inherited subprogram's parent + -- subprogram is not itself hidden. (Note: This condition could probably + -- be simplified, leaving out the testing for the specific controlled + -- cases, but it seems safer and clearer this way, and echoes similar + -- special-case tests of this kind in other places.) + if Present (Overridden_Subp) - and then not Is_Hidden (Overridden_Subp) + and then (not Is_Hidden (Overridden_Subp) + or else + ((Chars (Overridden_Subp) = Name_Initialize + or else Chars (Overridden_Subp) = Name_Adjust + or else Chars (Overridden_Subp) = Name_Finalize) + and then Present (Alias (Overridden_Subp)) + and then not Is_Hidden (Alias (Overridden_Subp)))) then if Must_Not_Override (Spec) then Error_Msg_Sloc := Sloc (Overridden_Subp);