From patchwork Fri Sep 2 10:05:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 113093 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 1E78BB6F72 for ; Fri, 2 Sep 2011 20:05:32 +1000 (EST) Received: (qmail 19158 invoked by alias); 2 Sep 2011 10:05:27 -0000 Received: (qmail 19145 invoked by uid 22791); 2 Sep 2011 10:05:25 -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, 02 Sep 2011 10:05:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 88A282BB205; Fri, 2 Sep 2011 06:05:05 -0400 (EDT) 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 ELJT+8ZqWDqt; Fri, 2 Sep 2011 06:05:05 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 8E50E2BAF6B; Fri, 2 Sep 2011 06:05:04 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 8D3843FEE8; Fri, 2 Sep 2011 06:05:04 -0400 (EDT) Date: Fri, 2 Sep 2011 06:05:04 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Suppress false alarm "postcondition refers only to pre-state" Message-ID: <20110902100504.GA2492@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 This patch suppresses these false, which can occur when a postcondition contains a quantified expression. The following test should compile quietly. gnatmake -f -gnat2012 -gnatwa t.adb package T is procedure P (S : in out String) with Post => (for all C of S => C = C); end T; package body T is procedure P (S : in out String) is begin null; end P; end T; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-02 Bob Duff * sem_ch6.adb: (Check_Post_State): Suppress warning "postcondition refers only to pre-state" when the expression has not yet been analyzed, because it causes false alarms. This can happen when the postcondition contains a quantified expression, because those are analyzed later. This is a temporary/partial fix. (Process_Post_Conditions): Minor: change wording of warning. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 178459) +++ sem_ch6.adb (working copy) @@ -5551,9 +5551,16 @@ declare E : constant Entity_Id := Entity (N); begin - if Is_Entity_Name (N) - and then Present (E) - and then Ekind (E) in Assignable_Kind + -- ???Quantified expressions get analyzed later, so E can be + -- empty at this point. In this case, we suppress the + -- warning, just in case E is assignable. It seems better to + -- have false negatives than false positives. At some point, + -- we should make the warning more accurate, either by + -- analyzing quantified expressions earlier, or moving this + -- processing later. + + if No (E) or else + (Is_Entity_Name (N) and then Ekind (E) in Assignable_Kind) then Found := True; end if; @@ -5627,7 +5634,7 @@ Ignored := Find_Post_State (Arg); if not Post_State_Mentioned then - Error_Msg_N ("?postcondition only refers to pre-state", + Error_Msg_N ("?postcondition refers only to pre-state", Prag); end if; end if;