From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c80e6f742e73478f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!g19g2000yqe.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Ensuring postconditions in the face of exceptions Date: Fri, 12 Mar 2010 01:24:28 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <820d96c0-5d67-4b8c-8c5b-811ca4f1127e@g26g2000yqn.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1268385868 10708 127.0.0.1 (12 Mar 2010 09:24:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 12 Mar 2010 09:24:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g19g2000yqe.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:10512 Date: 2010-03-12T01:24:28-08:00 List-Id: Ludovic Brenta wrote on comp.lang.ada: > Consider the procedure: > > type T is private; -- completion elided > > generic > =A0 =A0with procedure Visit (Object : in out T); > procedure Refresh (Object : in out T; Dirty : in out T) is Sorry, I meant: procedure Refresh (Object : in out T; Dirty : in out Boolean) is > begin > =A0 =A0if Dirty then > =A0 =A0 =A0 Visit (Object); > =A0 =A0 =A0 Dirty :=3D False; > =A0 =A0end if; > exception > =A0 =A0when others =3D> > =A0 =A0 =A0 Dirty :=3D True; -- warnings here > =A0 =A0 =A0 raise; > end Refresh; > > GNAT says: > warning: assignment to pass-by-copy formal may have no effect > warning: "raise" statement may result in abnormal return (RM > 6.4.1(17)) > > The reason for the exception handler is to enforce a postcondition > that Dirty must be True if Visit raises an exception. However the > warnings suggest that the postcondition cannot be enforced this way. > How should I rewrite my code? > > -- > Ludovic Brenta.