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!g4g2000yqa.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 03:08:58 -0800 (PST) Organization: http://groups.google.com Message-ID: <3696058c-235f-4d58-87be-74172ca0248a@g4g2000yqa.googlegroups.com> References: <820d96c0-5d67-4b8c-8c5b-811ca4f1127e@g26g2000yqn.googlegroups.com> <4b9a098b$0$2339$4f793bc4@news.tdc.fi> 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 1268392138 26349 127.0.0.1 (12 Mar 2010 11:08:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 12 Mar 2010 11:08:58 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g4g2000yqa.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:10514 Date: 2010-03-12T03:08:58-08:00 List-Id: On Mar 12, 10:29=A0am, Niklas Holsti wrote: > Ludovic Brenta wrote: > > 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 > > 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? > > Perhaps change the mode of Dirty to > > =A0 =A0 Dirty : access T; > > and assign > > =A0 =A0 Dirty.all :=3D True; > > Or use a named access type instead of the anonymous access, as you prefer= . Heh. I was kind of hoping you wouldn't say that :) I should have been more specific; I think using an access type is ugly but I can't think of a better solution. Thanks. -- Ludovic Brenta.