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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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: g2news1.google.com!postnews.google.com!g11g2000yqe.googlegroups.com!not-for-mail From: Alex Mentis Newsgroups: comp.lang.ada Subject: Re: Ensuring postconditions in the face of exceptions Date: Sun, 14 Mar 2010 07:05:20 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8990d686-f703-4e9c-91b7-32410289983d@g11g2000yqe.googlegroups.com> References: <820d96c0-5d67-4b8c-8c5b-811ca4f1127e@g26g2000yqn.googlegroups.com> NNTP-Posting-Host: 134.240.200.28 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1268575521 7009 127.0.0.1 (14 Mar 2010 14:05:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 14 Mar 2010 14:05:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g11g2000yqe.googlegroups.com; posting-host=134.240.200.28; posting-account=CedHywoAAAAcVQwJt5x8TeyAwJA5ElaR User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9560 Date: 2010-03-14T07:05:20-07:00 List-Id: On Mar 12, 4:13=A0am, 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? > > -- > Ludovic Brenta. I think trying to "force" the parameter passing mode to a certain mode is making this more complicated than necessary. One of the nice things about Ada over other languages is that you generally shouldn't have to worry about whether a parameter is copy-by-value or copy-by- reference. In this case, you are trying to use the exception handler to assign a value to the local parameter Dirty so that it can get passed back to the calling subprogram. This implies the calling subprogram has a parameter in its scope that keeps track of dirtiness, too. Instead of trying to set Dirty to True in Refresh, why not just raise a user- defined exception (such as Dirty_Error) and have an exception handler in the calling subprogram that catches this exception and sets the *calling subprogram's* variable tracking dirtiness to True? Alex