From patchwork Thu Oct 7 13:22:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 67058 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 1D0F3B6F11 for ; Fri, 8 Oct 2010 00:22:33 +1100 (EST) Received: (qmail 27333 invoked by alias); 7 Oct 2010 13:22:29 -0000 Received: (qmail 27323 invoked by uid 22791); 7 Oct 2010 13:22:27 -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; Thu, 07 Oct 2010 13:22:23 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id E8745CB0223; Thu, 7 Oct 2010 15:22:20 +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 mAfqpurRrwz3; Thu, 7 Oct 2010 15:22:20 +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 D5332CB01D4; Thu, 7 Oct 2010 15:22:20 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id B6236D9BB5; Thu, 7 Oct 2010 15:22:20 +0200 (CEST) Date: Thu, 7 Oct 2010 15:22:20 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Actual for a formal derived non-limited type Message-ID: <20101007132220.GA14160@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 a formal derived type is non-limited, an actual for it cannot be limited. This rule is needed to prevent anomalies with limited interfaces, because an extension of a limited interface is not limited if the appropriate keyword does not appear in the declaration. Without this rule, it would be possible to constructs assignments for limited types, as shown below. In Ada2012, the following program must be rejected: gcc -c -gnat12 derived.adb derived.adb:10:45: actual for non-limited "T" cannot be a limited type derived.adb:10:45: instantiation abandoned derived.adb:21:04: "Store" is undefined --- procedure Derived is type Ifc is limited interface; generic type T is abstract new Ifc with private; -- T is nonlimited: 7.5(6.1/2) procedure Classwide_Store (Target : out T'Class; Source : T'Class); procedure Classwide_Store (Target : out T'Class; Source : T'Class) is begin Target := Source; end Classwide_Store; procedure Store is new Classwide_Store (Ifc); -- legal? (No.) task type Tsk; task body Tsk is begin null; end Tsk; type Has_Task is limited new Ifc with record F : Tsk; end record; X, Y : Has_Task; begin Store (X, Y); end; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-07 Ed Schonberg * sem_ch12.adb (Validate_Derived_Type_Instance): If a formal derived type is non-limited, an actual for it cannot be limited. Index: sem_ch12.adb =================================================================== --- sem_ch12.adb (revision 165103) +++ sem_ch12.adb (working copy) @@ -9969,12 +9969,13 @@ -- interface then the generic formal is not unless declared -- explicitly so. If not declared limited, the actual cannot be -- limited (see AI05-0087). - -- Disable check for now, limited interfaces implemented by - -- protected types are common, Need to update tests ??? + -- Even though this AI is a binding interpretation, we enable the + -- check only in Ada2012 mode, because this improper construct + -- shows up in user code and in existing B-tests. if Is_Limited_Type (Act_T) and then not Is_Limited_Type (A_Gen_T) - and then False + and then Ada_Version >= Ada_12 then Error_Msg_NE ("actual for non-limited & cannot be a limited type", Actual,