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,1888e8caa20a2f2d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Controlled types and exception safety References: <8sKdnXNeIZMxIg3eRVn-ig@comcast.com> <3trncoj4t0va.19bs46zhm4xbe.dlg@40tude.net> In-Reply-To: <3trncoj4t0va.19bs46zhm4xbe.dlg@40tude.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2Rklf.171$n1.114@newsread2.news.pas.earthlink.net> Date: Tue, 06 Dec 2005 18:34:38 GMT NNTP-Posting-Host: 67.3.177.28 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1133894078 67.3.177.28 (Tue, 06 Dec 2005 10:34:38 PST) NNTP-Posting-Date: Tue, 06 Dec 2005 10:34:38 PST Xref: g2news1.google.com comp.lang.ada:6753 Date: 2005-12-06T18:34:38+00:00 List-Id: Dmitry A. Kazakov wrote: > generic > type Object is limited private; > with procedure Deep_Copy (Left : in out Object; Right : Object) is <>; > package Container is > ... > end Container; > ------------------------------- > with Container; > generic > type Object is private; > package Specialized_Container is > procedure Deep_Copy (Left : in out Object; Right : Object); > pragma Inline (Deep_Copy); > package Copying_By_Assignment is new Container (Object); > end Specialized_Container; > ------------------------------- > package body Specialized_Container is > procedure Deep_Copy (Left : in out Object; Right Object) is > begin > Left := Right; > end Deep_Copy; > end Specialized_Container; There's a gotcha in here. Suppose we have subtype S is Integer range 3 .. 4; and we instantiate package S_Container is new Specialized_Container (Object => S); Now suppose that Container has something like procedure Op (Item : in Object) is X : Object; begin -- Op Deep_Copy (Left => X, Right => Item); ... end Op; This is actually quite likely for a container, except X will be a component of the structure. For scalars, there is a check on "in" and "in out" parameters that the actual value is of the subtype; Constraint_Error is raised if it is not. The check is likely to fail in this case; X probably is not in 3 .. 4. So, for Container to work correctly for all possible actual types, the assignment procedure must have Left be mode "out". Now the uninitialized actual for Left is not checked on entry to the procedure, and it works correctly for scalars. For composite types, there is a whole collection of situations in which "out" really means "in out", so the user can still write a meaningful procedure that can inspect the contents of Left. Personally, I would have preferred procedure R'Assign (To : in out R; From : in R); for any record type R. This can be redefined by the user: for R'Assign use My_Assignment_Procedure; I have seen objections to this approach, but none that aren't handled by one of the following rules: * Within the body of a procedure used to implement 'Assign, ":=" refers to the predefined, bitwise copy assignment. or * There exists a procedure R'Bitwise_Copy (To : in out R; From : in R); that cannot be redefined by the user and is the default procedure for R'Assign. 'Bitwise_Copy can be called explicitly inside a procedure used to implement 'Assign to invoke default assignment. Perhaps I'm missing something, but in any case, it's an elephant. -- Jeff Carter "English bed-wetting types." Monty Python & the Holy Grail 15