From patchwork Fri Feb 17 13:57:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 141824 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 12007B6FA2 for ; Sat, 18 Feb 2012 00:57:53 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1330091875; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=lqMH9lCmJvRrRqkF4TpE 0l/smVg=; b=Zz+zkhJgmlXMhsGfup5M4DDFuTwnlggSqSx1JvYhXtXanz24J59X Fw3+ns3rvDhHioPtYjYYvEbclDS8qW3784hnQbpPpmcHI2lH7ufZbBG2baqUIykN 1nmXsuTVyxB8RFcqY6Sh66CbvCYC4BXakHDkwW0f6jWJ+8BlS5DbEg8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fR0HoVzO3ty+vempMcI+G+61Db6LaNnoLbGkmb37oIQelwZanJ3lqTHmVM5BVa QkYyIx2CCjBOhyZZXTMyfw/jwn+Am14d93g4Qoh4Jc59YpW5+EhmrERva4CdO1l6 dpuMIFF4RKxgEoMrrbJ2FVJA+fnyzZWGBPKEIrLCFmPNM=; Received: (qmail 7028 invoked by alias); 17 Feb 2012 13:57:48 -0000 Received: (qmail 7017 invoked by uid 22791); 17 Feb 2012 13:57:46 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Feb 2012 13:57:31 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C54C01C6B3D; Fri, 17 Feb 2012 08:57:30 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id B6lgGitAghZT; Fri, 17 Feb 2012 08:57:30 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 956831C6B3C; Fri, 17 Feb 2012 08:57:30 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 84A1B92BF6; Fri, 17 Feb 2012 08:57:30 -0500 (EST) Date: Fri, 17 Feb 2012 08:57:30 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Better warning for failure to override an abstract operation in an instance Message-ID: <20120217135730.GA26792@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 An operation declared in the private part of a generic package is overriding in an instane only if it was overriding in the generic. If an instantiation fails because a non-abstract type has a remaining abstract inherited operation it may be because of a failure to override. This patch produces a warning in this case, that clarifies the resulting error message. compiling inst.ads must yield: inst.ads:5:04: instantiation error at gen.ads:7 inst.ads:5:04: type must be declared abstract or "Change" overridden inst.ads:5:04: "Change" has been inherited at gen.ads:5, instance at line 5 inst.ads:5:04: "Change" has been inherited from subprogram at line 4 inst.ads:5:04: warning: in instantiation at gen.ads:8 inst.ads:5:04: warning: private operation "Change" in generic unit does not override any primitive operation of "Der" (RM 12.3 (18)) --- with P1; with Gen; package Inst is type Act is abstract new P1.Root with null record; procedure Change (Obj : Act) is abstract; package Prob is new Gen (Act); end Inst; --- package P1 is type Root is abstract tagged null record; end P1; --- with P1; generic type Ext is abstract new P1.Root with private; package Gen is type Der is new Ext with private; private type Der is new Ext with null record; procedure Change (Obj : Der); end Gen; Tested on x86_64-pc-linux-gnu, committed on trunk 2012-02-17 Ed Schonberg * sem_ch6.adb (Is_Non_Overriding_Operation): Add warning if the old operation is abstract, the relevant type is not abstract, and the new subprogram fails to override. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 184330) +++ sem_ch6.adb (working copy) @@ -188,9 +188,9 @@ New_E : Entity_Id) return Boolean; -- Enforce the rule given in 12.3(18): a private operation in an instance -- overrides an inherited operation only if the corresponding operation - -- was overriding in the generic. This can happen for primitive operations - -- of types derived (in the generic unit) from formal private or formal - -- derived types. + -- was overriding in the generic. This needs to be checked for primitive + -- operations of types derived (in the generic unit) from formal private + -- or formal derived types. procedure Make_Inequality_Operator (S : Entity_Id); -- Create the declaration for an inequality operator that is implicitly @@ -7844,6 +7844,22 @@ -- If no match found, then the new subprogram does not -- override in the generic (nor in the instance). + -- If the type in question is not abstract, and the subprogram + -- is, this will be an error if the new operation is in the + -- private part of the instance. Emit a warning now, which will + -- make the subsequent error message easier to understand. + + if not Is_Abstract_Type (F_Typ) + and then Is_Abstract_Subprogram (Prev_E) + and then In_Private_Part (Current_Scope) + then + Error_Msg_Node_2 := F_Typ; + Error_Msg_NE + ("private operation& in generic unit does not override " & + "any primitive operation of& (RM 12.3 (18))?", + New_E, New_E); + end if; + return True; end; end if;