From patchwork Mon Oct 11 08:24:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 67387 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 CE57DB6F07 for ; Mon, 11 Oct 2010 19:24:48 +1100 (EST) Received: (qmail 7679 invoked by alias); 11 Oct 2010 08:24:43 -0000 Received: (qmail 7669 invoked by uid 22791); 11 Oct 2010 08:24:40 -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, 11 Oct 2010 08:24:33 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6F221CB026B; Mon, 11 Oct 2010 10:24:31 +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 knpxPd2OD5Px; Mon, 11 Oct 2010 10:24:31 +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 535E9CB01EC; Mon, 11 Oct 2010 10:24:31 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 381BBD9BB5; Mon, 11 Oct 2010 10:24:31 +0200 (CEST) Date: Mon, 11 Oct 2010 10:24:31 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Better warnings on Ada95/Ada05 incompatibility with limited types Message-ID: <20101011082431.GA5944@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 This patch improves the warnings given in generic units whose instantiation would violate the Ada05 rules concerning the return of limited objects. Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-11 Ed Schonberg * sem_ch6.adb (Check_Limited_Return): Specialize warning on limited returns when in a generic context. (Analyze_Function_Return): ditto. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 165271) +++ sem_ch6.adb (working copy) @@ -495,8 +495,16 @@ package body Sem_Ch6 is -- In GNAT mode, this is just a warning, to allow it to be -- evilly turned off. Otherwise it is a real error. + -- In a generic context, simplify the warning because it makes + -- no sense to discuss pass-by-reference or copy. + elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then - if Is_Immutably_Limited_Type (R_Type) then + if Inside_A_Generic then + Error_Msg_N + ("return of limited object not permitted in Ada2005 " & + "(RM-2005 6.5(5.5/2))?", Expr); + + elsif Is_Immutably_Limited_Type (R_Type) then Error_Msg_N ("return by reference not permitted in Ada 2005 " & "(RM-2005 6.5(5.5/2))?", Expr); @@ -512,9 +520,11 @@ package body Sem_Ch6 is return; -- skip continuation messages below end if; - Error_Msg_N - ("\consider switching to return of access type", Expr); - Explain_Limited_Type (R_Type, Expr); + if not Inside_A_Generic then + Error_Msg_N + ("\consider switching to return of access type", Expr); + Explain_Limited_Type (R_Type, Expr); + end if; end if; end Check_Limited_Return; @@ -764,16 +774,25 @@ package body Sem_Ch6 is and then Object_Access_Level (Expr) > Subprogram_Access_Level (Scope_Id) then - Rewrite (N, - Make_Raise_Program_Error (Loc, - Reason => PE_Accessibility_Check_Failed)); - Analyze (N); - Error_Msg_N - ("cannot return a local value by reference?", N); - Error_Msg_NE - ("\& will be raised at run time?", - N, Standard_Program_Error); + -- Suppress the message in a generic, where the rewriting + -- is irrelevant. + + if Inside_A_Generic then + null; + + else + Rewrite (N, + Make_Raise_Program_Error (Loc, + Reason => PE_Accessibility_Check_Failed)); + Analyze (N); + + Error_Msg_N + ("cannot return a local value by reference?", N); + Error_Msg_NE + ("\& will be raised at run time?", + N, Standard_Program_Error); + end if; end if; if Known_Null (Expr) @@ -4255,9 +4274,11 @@ package body Sem_Ch6 is declare Typ : constant Entity_Id := Etype (Designator); Utyp : constant Entity_Id := Underlying_Type (Typ); + begin if Is_Immutably_Limited_Type (Typ) then Set_Returns_By_Ref (Designator); + elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then Set_Returns_By_Ref (Designator); end if;