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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Community Input for the Maintenance and Revision of the Ada Programming Language Date: Wed, 13 Sep 2017 21:41:18 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <915874b5-52c0-4aa8-9023-82fddedb816f@googlegroups.com> <67345f73-530c-400b-9eb4-63eeb440154c@googlegroups.com> <9a6338d9-83be-4e45-b8b7-edc56e33537f@googlegroups.com> <2deb28e2-f7e8-4461-b8b8-c2c6cf2784aa@googlegroups.com> <5de470d2-aa3d-4c02-ae2b-266c33a289fe@googlegroups.com> <5126ef7a-3324-4e44-b110-5e4838189f5f@googlegroups.com> <3c76c2ed-319f-410c-8dec-6a80a0948c7a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 13 Sep 2017 19:41:19 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="60900a2ca6147aba98685746e2b76f79"; logging-data="21964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18E8eVPaYOujH2tZKGKLxxNtE2nIXsxLuo=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:QXo5BUchAkV4WUjJ6zy0p9Cn7aU= Xref: news.eternal-september.org comp.lang.ada:48109 Date: 2017-09-13T21:41:18+02:00 List-Id: On 09/13/2017 08:34 PM, Egil H H wrote: > On Wednesday, September 13, 2017 at 6:34:43 PM UTC+2, Jeffrey R. Carter wrote: >> >> No. If you supply a discriminant, the object is constrained to that subtype. >> Only is you do not supply a discriminant is the object unconstrained. >> > > That's wrong. > > "If a discriminated type has default_expressions for its discriminants, then unconstrained variables of the type are permitted, and the values of the discriminants can be changed by an assignment to such a variable." > See RM 3.7 (28) > http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-7.html Let's try it: procedure Egilhh is type R (D : Integer := 0) is null record; C : R (D => 3); begin -- Egilhh C := (D => 4); end Egilhh; $ gnatmake egilhh.adb gcc-6 -c egilhh.adb egilhh.adb:6:06: warning: incorrect value for discriminant "d" egilhh.adb:6:06: warning: "Constraint_Error" will be raised at run time gnatbind-6 -x egilhh.ali gnatlink-6 egilhh.ali $ ./egilhh raised CONSTRAINT_ERROR : egilhh.adb:6 discriminant check failed Unconstrained variables of the type are permitted, but so are constrained variables of the type. You declare an unconstrained variable by not providing a discriminant. You declare a constrained variable by providing the discriminant. This has been true since Ada 83. See the examples at the end of ARM 3.7.1: 15 Large : Buffer(200); -- constrained, always 200 characters -- (explicit discriminant value) Message : Buffer; -- unconstrained, initially 100 characters -- (default discriminant value) -- Jeff Carter "If a sperm is wasted, God gets quite irate." Monty Python's the Meaning of Life 56