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,9fb8e2af320d5b3e X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Bus error Date: Sat, 30 Jun 2007 11:29:45 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <0367891DA5DA7E408D42A860FA002F44B0CC48@sma2901.cr.eurocopter.corp> <1l4yqvxoid4n1.1u8eo4oo8ml4m$.dlg@40tude.net> <4685280c$0$14869$9b4e6d93@newsspool4.arcor-online.net> <46865672$0$23136$9b4e6d93@newsspool1.arcor-online.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1183217385 30528 192.74.137.71 (30 Jun 2007 15:29:45 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 30 Jun 2007 15:29:45 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:J/Sl+OROI+2JrQrLyvM8JRsYUAY= Xref: g2news1.google.com comp.lang.ada:16356 Date: 2007-06-30T11:29:45-04:00 List-Id: Georg Bauhaus writes: > Dmitry A. Kazakov wrote: >> On Fri, 29 Jun 2007 17:44:22 +0200, Georg Bauhaus wrote: >> >>> Dmitry A. Kazakov wrote: >>>> function Very_Positive return Integer is >>>> begin >>>> return -1; >>>> end Very_Positive; >>>> >>>> Oops : Positive renames Very_Positive; -- This is OK! > Oops will at some point raise Constraint error;... Dmitry's complaint is the above will NOT raise C_E. The subtype of Oops is Integer, not Positive, and its value is -1. Oops is a constant (even though it doesn't say so). The fact that "Positive" is completely ignored by the compiler is clearly a language design flaw. >From AARM-8.5.1: 6 An object_renaming_declaration declares a new view [of the renamed object] whose properties are identical to those of the renamed view. [Thus, the properties of the renamed object are not affected by the renaming_declaration. In particular, its value and whether or not it is a constant are unaffected; similarly, the constraints that apply to an object are not affected by renaming (any constraint implied by the subtype_mark of the object_renaming_declaration is ignored).] 6.a Discussion: Because the constraints are ignored, it is a good idea to use the nominal subtype of the renamed object when writing an object_renaming_declaration. >...how can a compiler > be supposed to known that some Integer function will *always* > return non-Positives? Indeed! Likewise, how is the _programmer_ supposed to know? >...What makes you think that the programmer > who has written the Oops doesn't know what he is > doing using a subtype, not a new type? > > I think it is a program design fault, if a fault at all (or a flaw as > Bub Duff notes). Yes, I agree with you and with my evil twin Bub ;-) that it is a flaw in the program. The programmer should have written: Oops : Integer renames Very_Positive; But it's exactly the sort of flaw that the compiler ought to be required to detect, and give an error at compile time. (Note that the compiler doesn't need to look inside the body of Very_Positive to detect the "flaw".) Actually, the programmer really should have written: Oops : constant Integer := Very_Positive; but that's a different story. - Bob