From patchwork Tue Jun 22 13:54:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56501 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 67F27B6EDD for ; Tue, 22 Jun 2010 23:54:14 +1000 (EST) Received: (qmail 6265 invoked by alias); 22 Jun 2010 13:54:08 -0000 Received: (qmail 6035 invoked by uid 22791); 22 Jun 2010 13:54:06 -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; Tue, 22 Jun 2010 13:54:01 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 93EFDCB026C; Tue, 22 Jun 2010 15:54:03 +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 QpkdV7rJHwMW; Tue, 22 Jun 2010 15:54:03 +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 5FC5ACB023D; Tue, 22 Jun 2010 15:54:03 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 5599FD9BB4; Tue, 22 Jun 2010 15:54:03 +0200 (CEST) Date: Tue, 22 Jun 2010 15:54:03 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [Ada] All assignments to abstract target objects must be disallowed Message-ID: <20100622135403.GA3487@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 was permitting assignments to target objects of abstract tagged types (such as when the target is a conversion to an abstract type or a formal parameter of an abstract type). The original code to catch this was only flagging the case where the target was of an interface type. The new test flags assignments to any abstract object, unless the assignment does not come from source (because there are cases where the front end generates such an assignment in the _assign operation of an abstract type). Compilation of the following package must report this error: abstract_assign_bug.adb:6:06: target of assignment operation must not be abstract package Abstract_Assign_Bug is type Root is abstract tagged private; type T1 is new Root with private; procedure Reset (X : in out Root'Class); private type Root is abstract tagged record I : Integer:= 11; end record; type T1 is new Root with record J : Integer:= 22; end record; end Abstract_Assign_Bug; package body Abstract_Assign_Bug is procedure Reset (X : in out Root'Class) is Y : T1; begin Root (X):= Root (Y); -- ERROR: assignment to abstract target end Reset; end Abstract_Assign_Bug; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-22 Gary Dismukes * sem_ch5.adb (Analyze_Assignment): Revise test for illegal assignment to abstract targets to check that the type is tagged and comes from source, rather than only testing for targets of interface types. Remove premature return. Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 161073) +++ sem_ch5.adb (working copy) @@ -448,14 +448,14 @@ package body Sem_Ch5 is end if; return; - -- Enforce RM 3.9.3 (8): left-hand side cannot be abstract + -- Enforce RM 3.9.3 (8): the target of an assignment operation cannot be + -- abstract. This is only checked when the assignment Comes_From_Source, + -- because in some cases the expander generates such assignments (such + -- in the _assign operation for an abstract type). - elsif Is_Interface (T1) - and then not Is_Class_Wide_Type (T1) - then + elsif Is_Abstract_Type (T1) and then Comes_From_Source (N) then Error_Msg_N - ("target of assignment operation may not be abstract", Lhs); - return; + ("target of assignment operation must not be abstract", Lhs); end if; -- Resolution may have updated the subtype, in case the left-hand